Python Forum
Thread Rating:
  • 2 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
' | ' Operator and 'OR'
#5
When in doubt, break it down!
>>> def divis(n, x, y):
...   print(f"n%x = {n % x}")
...   print(f"n%y = {n % y}")
...   print(f"(n%x) | (n%y) = {(n%x) | (n%y)}")
...   print(f"n % x | n % y = {n % x | n % y}")
...
>>> divis(12, 3, 5)
n%x = 0
n%y = 2
(n%x) | (n%y) = 2
n % x | n % y = 2
If a value is divisible, it'd be 0. If either value is not divisible, then the bit-or will return that non-zero number (the remainder, which happens to be 2 in this case). Using the or keyword should work the same.
Reply


Messages In This Thread
' | ' Operator and 'OR' - by blackknite - Jan-10-2019, 01:10 AM
RE: ' | ' Operator and 'OR' - by stullis - Jan-10-2019, 02:24 AM
RE: ' | ' Operator and 'OR' - by blackknite - Jan-10-2019, 04:47 PM
RE: ' | ' Operator and 'OR' - by stullis - Jan-10-2019, 06:28 PM
RE: ' | ' Operator and 'OR' - by nilamo - Jan-10-2019, 06:40 PM
RE: ' | ' Operator and 'OR' - by Gribouillis - Jan-10-2019, 06:54 PM
RE: ' | ' Operator and 'OR' - by nilamo - Jan-10-2019, 07:08 PM
RE: ' | ' Operator and 'OR' - by blackknite - Jan-10-2019, 11:08 PM
RE: ' | ' Operator and 'OR' - by stullis - Jan-11-2019, 01:23 AM
RE: ' | ' Operator and 'OR' - by nilamo - Jan-11-2019, 05:51 AM
RE: ' | ' Operator and 'OR' - by blackknite - Jan-11-2019, 09:32 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020