Show Menu
Cheatography

Basic Python Cheat Sheet (DRAFT) by

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

Data Types

str =
"­str­ing­", 'string', "­"­"­mul­tiline string­"­"­"
int =
1
float =
1.10
bool =
True/False
list =
[element1, element2, element3, ...]
tuple =
(element1, element2, element3, ...)
dictionary =
{key1: value1, key2: value2}
dictio­nar­y[key] =
value
#
line comment

Operators

==
equal to
!=
not equal to
<
less than
>
greater than
<=
less than or equal to
>=
greater than or equal to
%
modulo (find the remainder)
**
exponent
+ - * /
add, subtract, multiply, divide
|
union
&
inters­ection
- ^
inclusion relations

Function

print()
info you want on the screen
type()
find variable type
int()
convert variable to integer
str()
convert variable to string
float()
convert variable to float
len()
find variable length
input()
request info from user
 

String Methods

(name.u­pp­er())
all upper case
(name.l­ow­er())
all lower case
(name.c­ap­ita­lize())
first letter to upper & all others lower
(name.t­it­le())
first letter of each word upper & all others lower