|
Python Operators
|
This was referenced from w3schools.com.
|
Python Operators
|
Operator
+ - * / % ** // |
Name
Addition Subtraction Multiplication Division Modulus Exponentiation Floor Division |
Example
x + y x - y x * y x / y x % y x ** y x // y |
Operator
= += -= *= /= %= **= //= &= |= ^= >>= <<= |
Example
x = 5 x += 3 x -= 3 x *= 3 x /= 3 x %= 3 x **= 3 x //= 3 x &= 3 x |= 3 x ^= 3 x >>= 3 x <<= 3 |
Same As
x = 5 x = x + 3 x = x - 3 x = x * 3 x = x / 3 x = x % 3 x = x ** 3 x = x // 3 x = x & 3 x = x | 3 x = x ^ 3 x = x >> 3 x = x << 3 |
Operator
== != > < >= <= |
Name
Equal Not equal Greater than Less than Greater than or equal to Less than or equal to |
Example
x == y x != y x > y x < y x >= y x <= y |
Operator
and or not |
Description
Returns True if both statements are true Returns True if one of the statements is true Returns True if one of the statements is true |
Example
x < 5 and x < 10 x < 5 or x < 4 not(x < 5 and x < 10) |
Operator
& | ^ ~ << >> |
Name
AND OR XOR NOT Zero fill left shift Signed right shift |
Example
Sets each bit to 1 if both bits are 1 Sets each bit to 1 if one of two bits is 1 Sets each bit to 1 if only one of two bits is 1 Inverts all the bits Shift left by pushing zeros in from the right and let the leftmost bits fall off Shift right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off |