Python Operators and Booleans Cheat Sheet
by Nouha_Thabet via cheatography.com/103894/cs/21322/
Python Arithmetic Operators Boolean Values Python Membership Operators
Addition 9 + 2 >> 11 In programming you often need to know if in Returns True if a sequence with the
Subtraction 9 - 2 >> 7 an expression is True or False. specified value is present in the object
You can evaluate any expression in x in y
Multiplication 9 * 2 >> 18
Python, and get the answer.
not Returns True if a sequence with the
Division 9 / 2 >> 4.5
print(5 < 8) >>> True in specified value is not present in the
Modulus 9 % 2 >> 1
print(5 > 8) >>> False object
Exponentiation 3 ** 2 >> 81
x not in y
Floor division 9 // 2 >> 4 Python Logical Operators
and Returns True if both statements are Python Bitwise Operators
Python Assignment Operators true & AND Sets each bit to 1 if both bits
Operator Example Same As x < 5 and x < 10 are 1
= x = 2 x = 2 or Returns True if one of the statements | OR Sets each bit to 1 if one of
+= x += 2 x = x + 2 is true two bits is 1
-= x -= 2 x = x - 2 x < 5 or x < 4 ^ XOR Sets each bit to 1 if only one
of two bits is 1
*= x *= 2 x = x * 2 not Reverse the result, returns False if
the result is true ~ NOT Inverts all the bits
/= x /= 2 x = x / 2
not(x < 5 and x < 10) << Zero Shift left by pushing zeros in
%= x %= 2 x = x % 2
fill left from the right and let the
//= x //= 2 x = x // 2 Python Identity Operators shift leftmost bits fall off
**= x **= 2 x = x ** 2 >> Signed Shift right by pushing copies
is Returns true if both variables are the
same object right of the leftmost bit in from the
Python Comparison Operators shift left, and let the rightmost
x is y
bits fall off
Equal x == y
is Returns true if both variables are not
Not equal x != y not the same object
Greater than x > y x is not y
Less than x < y
Greater than or equal to x >= y
Less than or equal to x <= y
By Nouha_Thabet Published 7th December, 2019. Sponsored by Readable.com
cheatography.com/nouha- Last updated 5th December, 2019. Measure your website readability!
thabet/ Page 1 of 1. https://readable.com