Show Menu
Cheatography

Python Cheat Sheet (DRAFT) by

Essential Python methods

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Arithmetic Operators

+ Addition
print(3 + 5) # 8
- Subtra­ction
print(8 - 6) # 2
* Multip­lic­ation
print(1 + 2 + 3 * 3) # 12
/ Division
print(8 / 4) # 2
% Mod (the remainder after dividing)
print(9 % 2) # 1
** Expone­nti­ation
print(3 ** 2) # 9
// Divides and rounds down to the nearest integer
print (16 // 3) # 5

Logical Operators

and
Evaluates if all provided statements are True
5 < 3 and 5 == 5 # False
or
Evaluates if at least one of many statements is True
5 < 3 or 5 == 5 # True
not
Flips the Bool Value
not 5 < 3 # True
 

Assignment Operators

x = 3 y= 4 z=5
x, y, z = 3, 4, 5
+= Addition Assignment
a += 1 # a = a + 1
-= Subtra­ction Assignment
a -= 3 # a = a - 3
*= Multip­lic­ation Assignment
a = 4 # a = a 4
/= Division Assignment
a /= 3 # a = a / 3
%= Remainder Assignment
a %= 10 # a = a % 10
**= Exponent Assignment
a **= 10 # a = a ** 10
 

Comparison Operators

== Is Equal To
3 == 5 # False
!= Not Equal To
3 != 5 # True
> Greater Than
3 > 5 # False
< Less Than
3 < 5 # True
>= Greater Than or Equal To
3 >= 5 # False
<= Less Than or Equal To
3 <= 5 # True