Skip to main content

Documentation Index

Fetch the complete documentation index at: https://edgepython.com/llms.txt

Use this file to discover all available pages before exploring further.

Edge Python ships with 41 built-in functions. They’re first-class values: pass them around, store them in containers, alias them.
# All built-ins are real values
fns = [abs, len, str]
print([f(-3) for f in fns])

p = print
p("aliased")
Output
[3, 2, '-3']
aliased

Output

print

print(*args) — write space-separated values to stdout, followed by a newline.
print(1, 2, 3)
print("hello", "world")
print()
Output
1 2 3
hello world

input

input() — read a line from stdin. Always returns an empty string in sandbox mode; there’s no host stdin in WebAssembly.

Numeric

abs

abs(x) — absolute value.
print(abs(-7))
print(abs(3.14))
print(abs(-2 ** 100))
Output
7
3.14
1267650600228229401496703205376

round

round(x) or round(x, n) — banker’s rounding (ties go to even).
print(round(2.5))
print(round(0.5))
print(round(-1.5))
print(round(1.55, 1))
Output
2
0
-2
1.6

min, max

Variadic, or accepting a single iterable.
print(min(3, 1, 4))
print(max([3, 1, 4]))
print(min("hello"))
Output
1
4
e

sum

sum(iterable) or sum(iterable, start).
print(sum([1, 2, 3]))
print(sum([1, 2, 3], 100))
print(sum(x * x for x in range(5)))
Output
6
106
30

pow

pow(base, exp) or pow(base, exp, mod) for modular exponentiation.
print(pow(2, 10))
print(pow(2, 10, 1000))
print(pow(7, 13, 19))
Output
1024
24
7

divmod

divmod(a, b)(a // b, a % b) as a tuple.
print(divmod(7, 3))
print(divmod(-7, 3))
Output
(2, 1)
(-3, 2)

bin, oct, hex

Format an integer as a base-2, base-8, or base-16 string with prefix.
print(bin(10))
print(oct(8))
print(hex(255))
print(hex(-256))
Output
0b1010
0o10
0xff
-0x100

Type conversion

int

print(int(3.9))
print(int("42"))
print(int(True))
Output
3
42
1

float

print(float(2))
print(float("3.14"))
Output
2.0
3.14

str

print(str(42))
print(str([1, 2, 3]))
print(str(None))
Output
42
[1, 2, 3]
None

bool

print(bool(0), bool(1))
print(bool([]), bool([0]))
print(bool(""), bool("x"))
Output
False True
False True
False True

list, tuple, set, dict

print(list("abc"))
print(tuple([1, 2, 3]))
print(set([1, 1, 2, 3]))
print(dict(a=1, b=2))
Output
['a', 'b', 'c']
(1, 2, 3)
{1, 2, 3}
{'a': 1, 'b': 2}

chr, ord

Convert between integer code points and single-character strings.
print(chr(65))
print(ord("A"))
Output
A
65

Sequence

len

print(len("hello"))
print(len([1, 2, 3, 4]))
print(len({"a": 1, "b": 2}))
print(len(range(100)))
Output
5
4
2
100

range

range(stop), range(start, stop), range(start, stop, step). Lazy.
print(list(range(5)))
print(list(range(2, 8)))
print(list(range(10, 0, -2)))
Output
[0, 1, 2, 3, 4]
[2, 3, 4, 5, 6, 7]
[10, 8, 6, 4, 2]

sorted

Returns a new sorted list.
print(sorted([3, 1, 4, 1, 5]))
print(sorted("hello"))
Output
[1, 1, 3, 4, 5]
['e', 'h', 'l', 'l', 'o']

reversed

Returns a list of elements in reverse order.
print(reversed([1, 2, 3]))
print(reversed("abc"))
Output
[3, 2, 1]
['c', 'b', 'a']

enumerate

Pairs each element with its index.
for i, v in enumerate(["a", "b", "c"]):
    print(i, v)
Output
0 a
1 b
2 c

zip

Pairs elements from N iterables, truncating to the shortest.
for a, b in zip([1, 2, 3], ["x", "y", "z"]):
    print(a, b)

print(list(zip([1, 2], [3, 4], [5, 6])))
Output
1 x
2 y
3 z
[(1, 3, 5), (2, 4, 6)]

Logical reductions

all, any

print(all([1, 2, 3]))
print(all([1, 0, 3]))
print(all([]))           # vacuous truth

print(any([0, 0, 1]))
print(any([0, 0, 0]))
print(any([]))
Output
True
False
True
True
False
False

Type and identity

type

print(type(42))
print(type("hi"))
print(type([1, 2]))
print(type(print))
Output
<class 'int'>
<class 'str'>
<class 'list'>
<class 'builtin_function_or_method'>

isinstance

print(isinstance(42, int))
print(isinstance(True, int))           # bool is a subtype of int
print(isinstance("x", (int, str)))     # tuple of types
Output
True
True
True

callable

print(callable(print))
print(callable(lambda x: x))
print(callable(42))
print(callable("hello"))
Output
True
True
False
False

id, hash

id(x) returns a unique identifier for the value. hash(x) returns a hash for hashable values.
x = 42
print(id(x) == id(x))
print(hash("hello") == hash("hello"))
print(hash((1, 2, 3)) == hash((1, 2, 3)))
Output
True
True
True
# Lists, dicts, sets are unhashable
try:
    hash([1, 2, 3])
except TypeError:
    print("unhashable")
Output
unhashable

Representation

repr

The “developer-readable” form. Quotes strings; renders containers with their elements as repr.
print(repr("hello"))
print(repr(42))
print(repr([1, "two", 3]))
Output
'hello'
42
[1, 'two', 3]

format

format(value) returns the display form. format(value, spec) is accepted but the spec is currently ignored — output is identical to display.
print(format(42))
print(format("hi"))
Output
42
hi

ascii

Like repr, but escapes non-ASCII characters with \uXXXX / \UXXXXXXXX.
print(ascii("café"))
print(ascii("hello"))
Output
'caf\u00e9'
'hello'

Attribute access

getattr and hasattr work against the built-in method tables on strings, lists, and dicts. Edge Python has no class system, so user-defined attributes don’t apply.

getattr

m = getattr("hello", "upper")
print(m())
print(getattr("hello", "missing", "default"))
Output
HELLO
default

hasattr

print(hasattr("hello", "upper"))
print(hasattr([1, 2], "append"))
print(hasattr("hello", "missing"))
Output
True
True
False

Built-in summary

FunctionArityNotes
printvariadicspace-separated, newline
input0empty string in sandbox
abs1int / float / BigInt
round1 or 2banker’s rounding
minvariadicor single iterable
maxvariadicor single iterable
sum1 or 2optional start
pow2 or 33-arg = modular
divmod2returns (q, r)
bin10b... prefix
oct10o... prefix
hex10x... prefix
int0 or 1parse / truncate
float0 or 1parse / cast
str0 or 1display form
bool0 or 1truthiness
list0 or 1from any iterable
tuple0 or 1from any iterable
set0 or 1from any iterable
dictvariadickwargs and/or single mapping
chr1int -> 1-char string
ord11-char string -> int
len1element count
range1, 2, or 3lazy integer sequence
sorted1new sorted list
reversed1reversed as list
enumerate1(index, value) pairs
zipvariadicparallel iteration
all1logical AND over iterable
any1logical OR over iterable
type1type name
isinstance2type or tuple of types
callable1True for functions, lambdas, types, builtins
id1unique identifier
hash1hash for hashable values
repr1developer-readable form
format1 or 2format spec currently ignored
ascii1repr with non-ASCII escapes
getattr2 or 3bound method or default
hasattr2True if method exists