Show Menu
Cheatography

Python Cheat Sheet (DRAFT) by

Basic python cheat sheet

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

Data Types

Integer
-256, 15
Float
-253.23, 1.253e-10
String
“Hello­", 'Goodbye', "­­"­"­­Mul­­ti­l­i­ne­­"­­"­"
List
[ value, ... ]
Tuple
( value, ... )
Dictionary
{ key: value, ... }

Loops

If Statem­ent
if expre­­ssion:
­ ­sta­t­ements
elif expre­­ssion:
­ ­sta­t­ements
else:
­ ­sta­t­ements

While Loop
while expre­­ssion:
­ ­sta­t­ements

For Loop
for var in colle­­ction:
­ ­sta­t­ements

Counting For Loop
for i in range(­­st­­art, end [, step]):
­ ­sta­t­ements
(start is included; end is not)

Arithmetic operators

Addition
x+y, x+=y
Divide
x/y, x/=y
Subtra­ction
x-y, x-=y
Mod
x%y, x%=y
Multip­lic­ation
xy, x=y
Exponent
xy, x=y

Comparison operators

Less
x<y
Less or equal
x<=y
Greater
x>y
Greater or equal
x>=y
Equal
x==y
Not equal
x!=y