The "Missing:"s below indicate that an entry is incomplete.
indentation | block (grouping statements, especially when statements are not expressions) |
\ | breaking lines (useful when end-of-line and/or indentation has a special meaning) |
# | commenting (until end of line) |
< > <= >= | comparison |
min / max | comparison (min / max (binary or more)) |
cmp | comparison (returns 3 values (i.e. inferior, equal or superior)) |
class X: """... """ def x(): """... """(2) | documentation comment |
== != | equality / inequality (deep) |
== <> | equality / inequality (deep) |
is / is not | equality / inequality (shallow) |
gc.collect() | force garbage collection |
( ... ) | grouping expressions |
inspect.stack()[0][2] inspect.stack()[0][1] | information about the current line and file |
eval | runtime evaluation |
case-sensitive | tokens (case-sensitivity (keywords, variable identifiers...)) |
CamelCase for classes, underscores for methods | tokens (if case sensitive, what is the standard way for scrunching together multiple words) |
[_a-zA-Z][_a-zA-Z0-9]* | tokens (variable identifier regexp) |
= | variable assignment or declaration (both) |
global | variable assignment or declaration (declaration) |
functools.partial(f, a) | partial application (in the examples below, a normal call is "f(a,b)") (give the first argument) |
lambda a, b: ... | anonymous function |
f(a,b,...) | function call |
f() | function call (with no parameter) |
__getattr__ | function called when a function is not defined (in dynamic languages) |
def f(para1, para2, ...): ... | function definition |
return | function return value (breaks the control flow) |
inspect.stack()[1] | runtime inspecting the caller information |
continue / break | breaking control flow (continue / break) |
return | breaking control flow (returning a value) |
try: a except exn: b | exception (catching) |
finally | exception (cleanup: code executed before leaving) |
continue | exception (retrying: after catching an exception, tell the snippet to be re-run) |
raise | exception (throwing) |
if c: b | if_then |
b1 if c else b2 | if_then_else |
if c: b1 elif c2: b2 else: b3 | if_then_else |
for i in range(10, 0, -1) | loop (for each value in a numeric range, 1 decrement) |
for i in range(1, 11) | loop (for each value in a numeric range, 1 increment (see also the entries about ranges)) |
for i in range(1, 11, 2) | loop (for each value in a numeric range, free increment) |
while (cond) expr | loop (while condition do something) |
; | sequence |
end-of-line | sequence |
super(Class, self).meth(args) | accessing parent method |
class | class declaration |
first parameter | current instance |
first parameter (48) | current instance |
__class__ | get the type/class corresponding to an object/instance/value |
hasattr(obj, "meth") (47) | has the method |
class child(parent): | inheritance |
__del__ | manually call an object's destructor |
object.method(para) | method invocation |
object.method() | method invocation (with no parameter) |
o.__class__.__dict__ (46) | methods available |
copy.copy(o) (43) | object cloning |
class_name(...) | object creation |
isinstance | testing class membership |
automatically done based on the file name | declare |
from p import * | import (everything into current namespace) |
import p | import (package (ie. load the package)) |
from p import name1, name2, ... | import (selectively) |
. | package scope |
s[n] | accessing n-th character |
chr | ascii to character |
ord | character to ascii |
str, `e`, repr | convert something to a string (see also string interpolation) |
* | duplicate n times |
s[n:m+1] | extract a substring |
find / index | locate a substring |
rfind / rindex | locate a substring (starting at the end) |
'''...''', """...""" | multi-line |
print (57) | simple print (on any objects) |
% | sprintf-like |
+ | string concatenation |
== != | string equality & inequality |
len | string size |
"\n" | strings (end-of-line (without writing the real CR or LF character)) |
'...' | strings (verbatim) |
"..." | strings (verbatim) |
'''...''', """...""" | strings (verbatim) |
"... %(v)s ..." % vars() | strings (with interpolation) |
upper / lower | upper / lower case character |
upper / lower | uppercase / lowercase / capitalized string |
Missing:
serialize (marshaling)
unserialize (un-marshaling)
False / None / 0 / "" / () / [] / {} | false value |
not | logical not |
or / and | logical or / and (short circuit) |
True / anything not false | true value |
bool | type name |
zip(*l) | 2 lists from a list of couples |
append | adding an element at the end (side-effect) |
reduce | f(... f(f(init, e1), e2) ..., en) |
for v in l ... | for each element do something |
pop | get the last element and remove it |
in | is an element in the list |
any | is the predicate true for an element |
all | is the predicate true for every element |
join | join a list of strings in a string using a glue string |
filter | keep elements matching |
[ x for x in l if p(x) ] (72) | keep elements matching |
a[-1] | last element |
+ | list concatenation |
[ a, b, c ] | list constructor |
zip | list of couples from 2 lists |
len | list size |
a[i] | list/array indexing |
reverse | reverse |
min / max | smallest / biggest element |
sort | sort |
sorted | sort |
map | transform a list (or bag) in another one |
[ f(x) for x in l ] (72) | transform a list (or bag) in another one |
map | transform two lists in parallel |
Missing:
adding an element at index
a, | computable tuple (these are a kind of immutable lists playing a special role in parameter passing) (1-uple) |
tuple([a]) | computable tuple (these are a kind of immutable lists playing a special role in parameter passing) (1-uple) |
() | computable tuple (these are a kind of immutable lists playing a special role in parameter passing) (empty tuple) |
*t | computable tuple (these are a kind of immutable lists playing a special role in parameter passing) (using a tuple for a function call) |
h.get(k, returned_value_when_k_unfound) | dictionary (access: read) |
h[k] | dictionary (access: read/write) |
{ a: b, c: d } | dictionary (constructor) |
has_key | dictionary (has the key ?) |
k in h | dictionary (has the key ?) |
k not in h | dictionary (has the key ?) |
keys | dictionary (list of keys) |
values | dictionary (list of values) |
del h[k] | dictionary (remove by key) |
None | optional value (null value) |
v | optional value (value) |
range | range (inclusive .. exclusive) |
. | record selector |
a, b, c | tuple constructor |
+ / - / * / / | addition / subtraction / multiplication / division |
& / | / ^ | bitwise operators (and / or / xor) |
<< / >> | bitwise operators (left shift / right shift / unsigned right shift) |
~ | bitwise operators (negation) |
divmod | euclidian division (both quotient and modulo) |
** | exponentiation (power) |
pow | exponentiation (power) |
log / log10 | logarithm |
% | modulo (modulo of -3 / 2 is 1) |
- | negation |
1000., 1E3 | numbers syntax (decimals) |
07, 0xf | numbers syntax (integers in base 2, octal and hexadecimal) |
1000 | numbers syntax (integers) |
mathematical | operator priorities and associativities (addition vs multiplication) |
mathematical | operator priorities and associativities (exponentiation vs negation (is -3^2 equal to 9 or -9)) |
sqrt / exp / abs | square root / e-exponential / absolute value |
sin / cos / tan | trigonometry (basic) |
asin / acos / atan (88) | trigonometry (inverse) |
int / round / floor / ceil | truncate / round / floor / ceil |
Missing:
random (random number)
random (seed the pseudo random generator)