Comments
# Single-line comment
x = 1 # Trailing comment
"""
Triple-quoted strings used as
module-level documentation are
parsed but discarded.
"""Identifiers and assignment
Identifiers follow Python rules: letters, digits, underscores, plus any non-ASCII letter.
0 0 0Tuple unpacking
1 2
1 [2, 3, 4] 5Walrus operator
Assignment as expression. Useful in conditions and comprehensions.
3Numbers
Integer literals: hex (0x), octal (0o), binary (0b). _ separates digits. Range and promotion: Data types, Integer.
3735928559
511
170
1000000Underscores are validated: 1_, 1__2, 0x_1, 1e_5 -> SyntaxError. Must sit between two digits.
3.14
1e-05
0.5
1e+16
5.0Complex literals (1j, 2+3j) are not part of the language.
Strings
single
double
triple
quoted
raw\n
hello worldEscape sequences
Supported: \n, \t, \r, \a, \b, \f, \v, \\, \', \", \0, \xHH, \uHHHH, \UHHHHHHHH, \NNN (1–3 octal digits). Named-char escapes (\N{GREEK SMALL LETTER ALPHA}) are not supported. Use \u.
line break
tab
A hex
é unicode
Af-strings
hello world
answer is 43
0042
3.142
0xff
'world'
{literal braces}Full format mini-language: [[fill]align][sign][#][0][width][,|_][.precision][type], with !r / !s / !a conversions before the spec. Type chars: b o c d e E f F g G n s x X %. The , and _ group digits (every three for decimals/floats; _ groups b/o/x/X every four).
Booleans and None
True False None
False True False True
FalseOperators
Arithmetic
10 4 21 2.3333333333333335
2 1 1024
-5 5/ always yields a float; // and % follow floored division (the result of % takes the divisor’s sign). With a string left operand, % is printf-style formatting instead of modulo (see Formatting).
Comparison and chaining
Ordering comparisons (<, >, <=, >=) work on numbers, strings, bytes, and tuples/lists (compared lexicographically). Mixing un-orderable types raises TypeError.
True
True
True
TrueLogical
Short-circuiting and / or return the operand, not a coerced bool:
second
fallback
defaultBitwise
1 7 6 -6
16 8Membership and identity
True
True
True
TrueAugmented assignment
+= -= *= /= //= %= **= &= |= ^= <<= >>=
30Conditional expression
bigContainers
Literals: [1, 2, 3] (list), (1, 2, 3) / (1,) / () (tuple), {"a": 1} (dict), {1, 2, 3} (set, empty is set() since {} is a dict). See Data types for semantics, mutation, methods.
Slicing
[2, 3, 4]
[1, 2]
[4, 5]
[1, 3, 5]
[5, 4, 3, 2, 1]Comprehensions
[0, 1, 4, 9, 16]
[0, 2, 4, 6, 8]
[(0, 0), (0, 1), (1, 0), (1, 1)]
{0: 0, 1: 1, 2: 4, 3: 9}
{1, 2, 0}Generator expressions consumed by reducers:
30
5Type annotations
Annotations parse on variables, parameters, and return positions but have no runtime effect. The parser drains them; they never reach the VM. No __annotations__, no runtime check. Treat them as docs for humans and static analysers.
7
ab