|
Assignment
|
= |
|
Arithmetic
|
+, -, *, /, % |
|
Comparison
|
>, >=, <, <=, ==, != |
|
Logical
|
not, and, or |
s.count(substring) |
Count occurences
|
s.find(substring) |
Index of first occurence
|
s.join(sequence) |
Concatenate sequence
|
s.split([delimiter]) |
Split into list
|
l.append(e) |
Add e
|
l.remove(e) |
Remove e
|
l.pop(e) |
Remove and return e
|
l.count(e) |
Count occurences
|
l.reverse() |
Reverse l
|
l.sort() |
Sort l
|
d.clear() |
Clear d
|
d.get(k) |
Return d[k]
|
d.keys() |
Return keys in d
|
d.values() |
Return values in d
|
d.items() |
Return key-value pairs in d
|
f = open(path) |
Open f
|
f.read() |
Read f
|
f.readline() |
Read line from f
|
f.readlines() |
Return list of lines in f
|
f.write(s) |
Write s to f
|
f.close() |
Close f
|
int(), float(), str(), bool()... |
Type casting
|
len(data) |
Length
|
min(values), max(values) |
Minimum / Maximum
|
pow(x,y, [z]) |
X to the power Y [mod Z]
|
range(start, stop, [step]) |
Ordered list
|
input(), print() |
Console Input/Output
|
filter(function, array) |
Filter array
|
map(function, array) |
Map function onto array
|
id(object) |
Unique object ID
|
round(n, [x]) |
Round n [x decimal places]
|
import module |
from module import submodule |
if(cond): <code> else: <code> |
If-else
|
if(cond1): <code> elif(cond1): <code> else: <code> |
If-elif-else
|
for i in range([start], stop, [step]): <code> |
For loop over range
|
for i in items: <code> |
For loop over iterable
|
while(condition): <code> |
While loop
|
break |
Exit first enclosing loop
|
continue |
Skip to next iteration
|
math, numpy, scipy |
Math
|
matplotlib |
Graph plotting
|
random |
Random generators
|
datetime |
Date and time
|
timeit |
Performance
|
re |
Regular expressions
|
os |
OS interaction
|
sys |
stdin, stdout, stderr, version
|
urllib |
Internet access
|
zlib |
Data compression
|
class Person: |
Class definition
|
x = Person(age, height) |
Object creation
|
x.age |
Field access
|
x.birthday() |
Method access
|
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.