The package registry is still being built. The docs are live, everything else is a preview.

Edge Python

Sign In

Sign in to publish packages and pin them by sha256.


By continuing, you accept our Terms and Conditions.

@
Palette

Data types

Type checks

cmd + enter
<class 'int'>
<class 'float'>
<class 'str'>
<class 'list'>
<class 'tuple'>
<class 'set'>
<class 'dict'>
<class 'NoneType'>
<class 'bool'>
Output

Use isinstance to test whether a value belongs to a type.

Integer

One int type with a signed 128-bit range, from -(2**127) to 2**127 - 1. Going out of range raises OverflowError. Details: Limits and errors. There is no complex type.

cmd + enter
170141183460469231731687303715884105727
overflow
Output

Float

IEEE-754 double precision. Mixing int and float in arithmetic yields a float.

cmd + enter
False
True
5.0
2
0
1.6
Output

Boolean

bool has two values, True and False. It is a subclass of int.

cmd + enter
True
2
Output

Which values count as true: Truthy and falsy below.

String

Immutable sequence of Unicode code points. Indexing returns a one-character string. len counts code points, not bytes. Iteration yields characters.

cmd + enter
h o
éll
5
héllo world
héllohéllo
True
Output

Literal forms, quotes, and escapes: Syntax. Methods: Methods.

Bytes

Immutable sequence of octets, each 0 to 255. bytes stores raw data, not text. Indexing returns an int, and iteration yields ints.

cmd + enter
b'hello'
5
104
b'ell'
97
98
99
Output

bytes never equals str, even for valid UTF-8. Non-ASCII characters in a bytes literal are stored as their UTF-8 encoding.

cmd + enter
False
b'\xc3\xa9'
Output

Encoding round-trips use str.encode and bytes.decode.

cmd + enter
b'Edge Python' Edge Python
Output

Constructor forms (bytes(), bytes(n), from an int iterable, from an encoded string): Builtins. Methods such as hex, split, and fromhex: Methods.

List

Mutable sequence. Assignment copies the reference, so aliases share mutations.

cmd + enter
[99, 2, 3, 4]
4
[99, 2, 3, 4, 5]
Output

Equality is structural.

cmd + enter
True
True
Output

Slice assignment with step 1 resizes the list in place. Slice deletion removes a range. Assigning into an empty slice inserts.

cmd + enter
[1, 20, 30, 40, 4, 5]
[1, 20, 4, 5]
[1, 99, 20, 4, 5]
Output

+= on a list extends it in place, so aliases see it.

cmd + enter
[1, 2, 3, 4]
Output

Tuple

Immutable sequence. A tuple is hashable when its elements are, which makes it the usual compound dict key.

cmd + enter
1
(1, 2, 3, 4, 5)
key
Output

Literal forms such as the trailing comma in (1,): Syntax.

Dict

Insertion-ordered mapping. Keys must be hashable: numbers, strings, bytes, bools, None, frozensets, and tuples of hashables. An unhashable key raises TypeError. Numerically equal keys collapse, so 1, 1.0, and True are one key and the latest assignment wins. Iteration yields keys.

cmd + enter
1
{'a': 1, 'b': 2, 'c': 3}
{1: 'bool'}
x
y
Output
cmd + enter
unhashable key
Output

Methods such as keys, values, items, and get: Methods.

Set

Unordered collection of unique, hashable values. The operators |, &, -, and ^ build new sets. The augmented forms |=, &=, and ^= update the set in place, so aliases observe the change. <= and < test subsets.

cmd + enter
4
[1, 2, 3, 4]
[1, 2, 3, 4]
[2, 3]
True
[1, 2, 3, 4, 5]
Output

The empty set is set(), since {} makes a dict (see Syntax). Named operations such as union and issubset: Methods.

Frozenset

Immutable, hashable set built with frozenset(iterable). It supports len, iteration, membership, unpacking, the algebra operators, and the subset comparisons. In mixed set and frozenset algebra the result takes the type of the left operand. A frozenset has no named methods. frozenset({1}).union({2}) raises AttributeError. Convert with set(fs) for the method API.

cmd + enter
3
True
[1, 2, 3]
<class 'frozenset'>
<class 'set'>
[1, 2, 3, 4]
True
ok
Output

Unpacking in literals

* spreads an iterable into a list or set literal. ** spreads a mapping into a dict literal. Both mix freely with regular elements. For dicts, later keys win.

cmd + enter
[1, 2, 3, 1, 2]
[1, 2, 3]
{'x': 9, 'y': 2}
Output

Range

Lazy integer sequence. range(stop), range(start, stop), or range(start, stop, step).

cmd + enter
[0, 1, 2, 3, 4]
[2, 3, 4, 5, 6, 7]
[0, 2, 4, 6, 8]
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
Output

NoneType

Single value, single type.

cmd + enter
None
True
<class 'NoneType'>
Output

Ellipsis

... is a singleton of type ellipsis. It compares equal only to itself and is distinct from the string '...'.

cmd + enter
Ellipsis
True
<class 'ellipsis'>
False
Output

Conversions

Every constructor (int, float, str, bool, list, tuple, set) doubles as a converter. The full matrix: Builtins. The two gotchas worth remembering:

cmd + enter
3
-3
False
True
Output

Truthy and falsy

Falsy values (everything else is truthy):

Falsy values
None
False
0, 0.0
"", b""
[], ()
{}, set(), frozenset()
range(0)
cmd + enter
False
False
False
False
True
True
Output