Edge Python
Esc

Go to

Commands

Sign In

Sign in to publish packages and pin them by sha256.


By continuing, you accept our Terms and Conditions.

@
Palette

Syntax

Comments

# starts a comment that runs to the end of the line.

# A comment on its own line
x = 1  # A trailing comment
python

A string literal as the first statement of a module, function, or class body parses and is discarded. There is no __doc__ at runtime.

Line joining

A statement continues on the next line after a trailing backslash, or freely inside (), [], and {}.

3 ['a', 'b']
Output

Identifiers and assignment

Identifiers start with a letter or underscore and continue with letters, digits, and underscores. Non-ASCII characters are allowed.

0 0 0
Output

Tuple unpacking

1 2
1 [2, 3, 4] 5
10 20
Output

Targets can also be attributes, subscripts, parenthesized lists, or nested patterns.

[1] 0
3 4 5 6 7
Output

for loops and comprehensions take the same nested targets, as in for i, (k, v) in enumerate(d.items()). A starred target such as *middle must be a plain name.

Walrus operator

:= assigns as an expression. Useful in conditions and comprehensions.

3
Output

Numbers

Integer literals are decimal by default, with 0x hex, 0o octal, and 0b binary forms. _ may separate digits. The value range and overflow behavior: Data types.

3735928559
511
170
1000000
Output

An underscore must sit between two digits. 1_, 1__2, and 0x_1 are rejected.

Float literals are IEEE-754 doubles.

3.14
1e-05
0.5
1e+16
Output

Complex literals such as 1j do not exist.

Strings

Strings take single, double, or triple quotes. An r prefix makes a raw string where backslashes stay literal. Adjacent literals concatenate into one. A b prefix builds bytes instead of a string.

single
double
triple
quoted
raw\n
hello world
Output

Escape sequences

Supported escapes are \n, \t, \r, \a, \b, \f, \v, \\, \', \", \0, \xHH, \uHHHH, \UHHHHHHHH, and \NNN with 1 to 3 octal digits. An unknown escape keeps its backslash. Named escapes such as \N{GREEK SMALL LETTER ALPHA} are not supported and stay literal.

 line break
	 tab
A hex
é unicode
A
Output

f-strings

hello world
answer is 43
0042
3.142
0xff
'world'
{literal braces}
Output

The format spec is [[fill]align][sign][#][0][width][,|_][.precision][type]. The conversions !r, !s, and !a come before the spec. Type characters are b c d e E f F g G n o s x X %. The , and _ options group digits, every three for decimal output and every four for _ with b, o, x, or X.

Booleans and None

The literals are True, False, and None. not negates. Truthiness rules: Data types.

True False None
False
Output

Operators

Arithmetic

10 4 21 2.3333333333333335
2 1 1024
-5 5
Output

/ always yields a float. @ has no builtin meaning and calls __matmul__. // and % use floored division, so the result of % takes the sign of the divisor. With a string on the left, % is printf-style formatting (see Methods).

3 of pies
Output

Comparison and chaining

Comparisons chain, in, not in, is and is not included, so a < b in c means a < b and b in c with b evaluated once. Ordering works on numbers, strings, bytes, and on lists or tuples compared lexicographically. Mixing types that cannot be ordered raises TypeError.

True
True
True
True
Output
cannot order
Output

Logical

and and or short-circuit and return the deciding operand, not a coerced bool.

second
fallback
default
Output

Bitwise

1 7 6 -6
16 8
Output

Membership and identity

True
True
True
True
True
Output

Augmented assignment

+= -= *= /= //= %= **= @= &= |= ^= <<= >>=. On a user class a op= b calls the in-place dunder such as __iadd__ first.

30
Output

Conditional expression

big
Output

Containers

Literal forms: [1, 2, 3] is a list, (1, 2, 3) a tuple, (1,) a one-element tuple, () an empty tuple, {"a": 1} a dict, {1, 2, 3} a set. {} is an empty dict, so the empty set is set(). Semantics and methods: Data types and Methods.

(1,) ()
<class 'dict'> <class 'set'>
Output

Indexing and slicing

Indices start at 0. Negative indices count back from the end. Slices take [start:stop:step], and any part may be omitted. A negative step walks backwards.

1 5
[2, 3, 4]
[1, 2]
[4, 5]
[1, 3, 5]
[5, 4, 3, 2, 1]
Output

Comprehensions

[0, 1, 4, 9, 16]
[0, 2, 4, 6, 8]
[(0, 0), (0, 1), (1, 0), (1, 1)]
[[], [0], [0, 1]]
{0: 0, 1: 1, 2: 4, 3: 9}
[0, 1, 2]
Output

Generator expressions: Functions.

Type annotations

Annotations parse on variables, parameters, and return positions. They have no runtime effect. There is no __annotations__ and no runtime check. Treat them as documentation for humans and static analyzers. Type parameters such as def f[T] are discarded the same way, and class Box[T] keeps them in __type_params__ so Box[int] is a generic alias, as is any class defining __class_getitem__. type X = v binds a lazy alias whose __value__ evaluates v, list[int] is a generic alias that prints as list[int] and builds a list when called, and int | None is a union that isinstance accepts.

7
ab
Output