60 built-in functions, all first-class values: pass as arguments, store in containers, alias.
[3, '-0x3', '-3']
aliasedEdge Python is multi-paradigm. Introspection helpers (eval, exec, compile, dir, ascii, help, __import__, breakpoint, open) are absent by design. The static-import contract and the lack of a writable global module table make them impossible or inconsistent with the paradigm. staticmethod / classmethod are omitted; use the namespace pattern or free functions. super and property are supported. See /language/classes, /language/dunders.
Output
print(*args, sep=' ', end='\n'): values joined by sep to stdout, then end. * unpacking spreads an iterable into the arguments. file / flush are accepted and ignored (the sandbox has one output stream).
1 2 3
a-b-c
no newline!
1, 2, 3input
input(): one line from the host buffer. Native: stdin. WASM: drains the buffer the host wrote via set_input. Empty buffer -> empty string. No prompt argument.
Numeric
abs
abs(x): absolute value of int or float. Non-numeric -> TypeError. Works across the full integer range (see Integer width).
7
3.14round
round(x) or round(x, n): banker’s rounding (ties go to even).
2
0
-2
1.6min, max
Variadic or single iterable. Accept a default= returned when a single iterable is empty; without it an empty input raises ValueError. A key= function selects the comparison value (the original element is returned). Ordering follows <: numbers, strings, bytes, and tuples/lists (lexicographic).
1
4
e
-1
0sum
sum(iterable) or sum(iterable, start). sum([]) returns 0.
6
106
30pow
pow(base, exp) or pow(base, exp, mod) for modular exp. 3-arg requires int operands and non-negative exp (pow(a, b, 0) -> ZeroDivisionError; pow(a, -1, m) -> ValueError). Modulus must be < 2^63 (larger overflows i128 in (result * base) % m), raises ValueError("pow() modulus too large; must be < 2^63").
1024
24
7divmod
divmod(a, b): (a // b, a % b) as a tuple. Ints or floats (float operands give a float quotient and remainder).
(2, 1)
(-3, 2)
(3.0, 1.5)bin, oct, hex
Format an integer as a base-2, base-8, or base-16 string with prefix.
0b1010
0o10
0xff
-0x100Type conversion
int
int(x): accepts int, bool, float (truncates toward zero), or a numeric string (with optional _ separators). int(s, base) parses a string in radix 2-36, or 0 to auto-detect a 0x / 0o / 0b prefix. Bad strings -> ValueError; int(inf) / int(nan) -> OverflowError / ValueError. Supports +/-2^127 (inline 47-bit + LongInt i128); wider -> OverflowError.
3
42
1
255
5
1000float
float(x): int, bool, float, or string. Strings recognise inf, -inf, nan (case-insensitive).
2.0
3.14
infstr
str(x): display form. No arg -> empty string. str(bytes, encoding) decodes the bytes.
42
[1, 2, 3]
None
hibool
False True
False True
False Truelist, tuple, set, frozenset, dict
list, tuple, set, frozenset accept any iterable: list, tuple, set, frozenset, dict (keys), range, bytes, str, generator, coroutine. Share an extract_iter helper, so all constructors are interchangeable.
['a', 'b', 'c']
(0, 1, 2)
{'b', 'a'}
frozenset({2, 3, 1})
{'a': 1, 'b': 2}dict also accepts a mapping or kwargs; iterable-of-pairs (dict([('a', 1)])) is not supported; use a literal or dict.update.
chr, ord
Convert between code points and single-char strings. chr accepts full Unicode (chr(0x1F600) -> "😀"); negative -> ValueError. ord requires a length-1 string; ord(b'A') not accepted.
A
65
😀Sequence
len
Element count for str (code points), bytes, list, tuple, dict, set, frozenset, range. Else TypeError.
5
4
2
100range
range(stop), range(start, stop), range(start, stop, step). Lazy. step=0 -> ValueError; non-int args -> TypeError. Two ranges compare equal when they produce the same value sequence: range(0) == range(1, 1) is True, range(5) == range(0, 5, 1) is True.
[0, 1, 2, 3, 4]
[2, 3, 4, 5, 6, 7]
[10, 8, 6, 4, 2]
Truesorted
New sorted list. Accepts key=fn and reverse=True/False. Numbers, strings, bytes, and tuples/lists order lexicographically; mixed un-orderable types raise TypeError.
[1, 1, 3, 4, 5]
['e', 'h', 'l', 'l', 'o']
[5, 4, 3, 1, 1]
['kiwi', 'apple', 'banana']reversed
Returns a list (eager, not a lazy iterator). For strings: list of length-1 strings. Operationally equivalent to a lazy iterator for finite inputs.
[3, 2, 1]
['c', 'b', 'a']enumerate
Pairs each element with its index -> list of (i, value) tuples. A second argument (positional or start=) sets the first index.
0 a
1 b
2 czip
Pairs N iterables, truncating to shortest. No strict=, pre-validate lengths if needed.
1 x
2 y
3 z
[(1, 3, 5), (2, 4, 6)]next
next(iterator) -> next item. Exhausted -> StopIteration. Two-arg next(it, default) returns default instead of raising on exhaustion.
10
20
30iter
iter(x) returns a fresh iterator over any iterable (list, tuple, set, dict, range, str, bytes, frozenset). Materialises a snapshot, original never mutated. Two-arg iter(callable, sentinel) calls callable() until it returns sentinel, eagerly.
1
2
amap
map(fn, *iterables) -> list of fn(items...). With several iterables they are walked in parallel, stopping at the shortest. Eager, full list materialises immediately; pipelines into sum, list, max.
[2, 4, 6]
30
[11, 22]
['hi', 'world']filter
filter(pred, iterable) -> list of items where pred(item) is truthy. None predicate filters by truthiness (equivalent to lambda x: x).
[3, 4]
[1, 'hi', [1]]import_module
import_module(name) returns a module previously imported statically. Runtime dispatch among pre-imported modules without a manual dict.
import prod_handler
import dev_handler
def handle(env, request):
return import_module(env + "_handler").handle(request)
handle("prod", req)
handle("dev", req)Candidates must be imported statically somewhere. import_module is a runtime lookup, not a fetch. It preserves lockfile and integrity: every reachable module is verified at compile time. Unknown name -> NameError. Non-module global -> TypeError.
Dynamic loading (importlib.import_module, __import__) doesn’t exist by design. Static-import plus runtime-dispatch replaces it.
bytes
Four forms:
bytes()-> emptybytes(n)->nzero bytesbytes(iterable)of ints in0..=255-> those valuesbytes(s, encoding)-> encoded ("utf-8","utf8","ascii"only; elseValueError)
b''
b'\x00\x00\x00\x00'
b'Hello'
b'caf\xc3\xa9'See Bytes for literal syntax (b"..."), indexing, slicing, methods.
bytes_fromhex, int_from_bytes, int_to_bytes
Free-function forms. The equivalent methods (bytes.fromhex, int.from_bytes, int.to_bytes) also exist and behave identically; use whichever reads better.
bytes_fromhex(s): hex string -> bytes. Inner whitespace ignored; non-hex ->ValueError.int_from_bytes(b, order):orderis"big"or"little". Unsigned (high bit never sign).int_to_bytes(n, length, order):n >= 0,length <= 8. Accepts inline ints orLongInt; doesn’t fit ->OverflowError.
b'Hello'
256
b'\x00\xff'Logical reductions
all, any
True
False
True
True
False
FalseType and identity
type
type(x) returns the type object for x, shown as <class 'name'>. Built-in type names (int, set, list, …) are these same objects. So type(x) is int and type(x) == int hold, and calling one constructs it (type([1])([2, 3]) gives [2, 3]). For a user instance, type(x) is its own class, so type(x) is C holds and its repr is qualified with the module (<class '__main__.C'>). No metaclass or dir.
<class 'int'>
<class 'str'>
<class 'list'>
<class 'builtin_function_or_method'>
True
[4, 5]
TrueFunctions, type objects, and user classes expose __name__ (the bare declared name). type(e) on an exception instance reports its concrete class, so type(e).__name__ yields the exception’s name.
greet
int
Box
ZeroDivisionErrorisinstance
isinstance(obj, X): X is a built-in type, exception class, user-defined Class, or tuple of any of those. String X (isinstance(x, "str")) -> TypeError. bool is a subtype of int. Exception classes walk the standard hierarchy (isinstance(e, Exception) matches any built-in exception). User classes walk the inheritance chain.
True
True
Trueissubclass
issubclass(C, B): both C and B are classes (B may be a tuple of classes). Arg 1 must itself be a class, or it raises TypeError. Built-in and exception classes walk the standard hierarchy (issubclass(ZeroDivisionError, Exception)), bool is a subclass of int, and user classes walk the inheritance chain.
True
True
True
True
Falsecallable
True for user functions, lambdas, bound methods, type objects, native builtins, and instances whose class defines __call__ (see Callable). False for everything else.
True
True
False
Falseid, hash
id(x): stable identifier (NaN-box bit pattern masked to int range). hash(x): hash for hashable values. hash(1) == hash(1.0), so int/float keys collapse to one dict slot.
True
True
TrueunhashableMutable containers used as dict keys / set members -> TypeError("unhashable type") at insertion (caught in store_item, BuildDict, build_set).
Representation
repr
Developer-readable form. Quotes strings; renders containers with element reprs.
'hello'
42
[1, 'two', 3]format
format(value) -> display form. format(value, spec) applies the f-string spec mini-language ([[fill]align][sign][#][0][width][,][.precision][type]). Width and precision are capped (precision at 65,000). A larger value raises ValueError rather than allocating an oversized string.
42
00042
3.14
0xff
hiAttribute access
getattr / hasattr / delattr consult the instance __dict__ first, then the user class chain (including inherited methods), then the built-in method table for primitives (str/bytes/list/dict/set, plus the small int/float method set), and class attributes on a class object. So hasattr(MyClass(), 'my_method') is True for a defined method, and delattr on a missing attribute raises AttributeError.
getattr
HELLO
defaulthasattr
True
True
Falseglobals, locals
globals(): fresh dict snapshot of module-level bindings (builtins, types, top-level assignments). locals(): fresh dict of the current frame: function locals inside a function, same as globals() minus builtins at module level.
300
7
{'b': 2, 'a': 1}Dicts are copies. Mutation doesn’t change VM bindings.
setattr, delattr
setattr(obj, name, value) / delattr(obj, name) store/remove on user instances and on user classes (cls.attr = ... works too). Builtin types have no writable attribute table.
42
Falseslice
slice(stop), slice(start, stop), slice(start, stop, step): reusable slice value usable as a sequence index.
[20, 30, 40]
[10, 30, 50]vars
vars(instance) -> attr-dict snapshot. vars(module) -> exported-names dict. Only instances and modules, no no-arg form (use locals()).
{'x': 1, 'y': 2}Classes
super
super(): zero-arg only. Proxy resolving attribute access against the bases of the current method’s class, starting one step up the MRO. Outside a method -> TypeError.
abproperty
property(fget, fset=None): descriptor for class members. Usually applied via @property with optional @<name>.setter.
9Async
Concurrency primitives. Full model in Async.
run
run(*coros): schedules every arg, drains until each reaches a terminal state, returns the first arg’s result. Errors from peers other than the first are discarded. For fan-out that collects every result, use gather.
sleep
sleep(seconds): yield and resume after the duration. Negative clamps to zero. Without a host time hook, a virtual clock advances. With one, the scheduler signals PendingTimer(deadline_ns) and the embedder resumes via run_resume.
frame
frame(): yield until the host’s next render frame. Coro -> WaitingFrame, scheduler signals PendingFrame. Browser embedders hook requestAnimationFrame. Use for animation loops at display refresh rate.
async def animate(node):
for i in range(60):
set_attribute(node, "style", f"transform: translateX({i}px)")
frame()receive
receive(): pop the oldest message from the scheduler queue. Empty -> parks in WaitingEvent, scheduler signals PendingEvent. Embedder resumes via run_push_event(bytes). Messages are arbitrary strings (e.g. DOM event names from bind_event).
gather
gather(*coros): concurrent fan-out. Schedules every arg, drains until each terminal, returns a list of results in argument order. First-error propagates after all peers terminal.
[2, 4, 6]with_timeout
with_timeout(seconds, coro): runs coro to completion or raises TimeoutError on deadline. Coro cancelled on timeout.
timed outcancel
cancel(coro): flag a registered coroutine for cancellation. The next tick stops it. Cooperative and silent: the body doesn’t observe CancelledError. For deadline-driven exception-style cancellation, use with_timeout.