Show Menu
Cheatography

Python Class Summary Cheat Sheet (DRAFT) by

Summary of my Uni's Python Class

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

Basic Python Functions

 

Operators and Comparing Values

+
Addition
-
Subtra­ction
*
Multip­lic­ation
/
Division
//
Integer Division
%
Modulus (Remai­nder)
==
equal
!=
not equal
>
greater than
<
smaller than
>=
greater than or equal
<=
smaller than or equal

Value Conversion

str()
converts value to a string
int
converts value to an integer
float()
converts value to a float
bool()
converts value to a boolean
 

Lists

sort()
reverse()
remove(item)
pop(position)
insert(position, item)
index(item)
extend(list)
count(item)
append(item)

Dictio­naries

d.update()
d.keys()
d.values()
d.items()
d.pop(key[,d­efault])
d.popi­tem()
d.get(key[,d­efault])
d.setd­efault(key[,d­efault])
d.clear()
del d[key]
d[key] = value
d = name of dictionary

HOW TO CREATE AND ACCESS A DICTIONARY AND ITS KEYS

Tuples

 
 

Strings

capita­lize()
endswith(sub)
strip()
join()
replace(old, new)
split(sep)
upper()*
lower()*
isalpha()*
isalnum()*
isdigit()*
isspace()*
islower()*
isupper()*
istitle()*
methods marked with * are applicable only for 8-bit strings

Ranges

 

Indexes and Slices

len(a)
6
a[0]
0
a[5]
5
a[-1]
5
a[-2]
4
a[1:]
[1,2,3­,4,5]
a[:5]
[0,1,2­,3,4]
a[:-2]
[0,1,2,3]
a[1:3]
[1,2]
a[1:-1]
[1,2,3,4]
b=a[:]
b = a = [0,1,2­,3,4,5]
a = [0,1,2­,3,4,5]

Datetime

today()
now(ti­mez­one­info)
utcnow()
fromti­mes­tamp(timestamp)
utcfro­mti­mes­tamp(timestamp)
combine(date, time)
IMPORT­??????

Math

square root
math.s­qrt()
greatest common divisor
math.gcd()
power
math.pow()
pi
math.pi
from math import*