Built-in functions
Always available, no import required.
I/O
| Function | Description |
|---|---|
print(...values) |
Print values separated by spaces, then a newline. |
write(...values) |
Like print but with no trailing newline. |
input([prompt]) |
Print the optional prompt, read one line from stdin (returns nil at EOF). |
Conversion & inspection
| Function | Description |
|---|---|
len(x) |
Length of a string, list, or dict. |
type(x) |
Type name ("number", "string", …; a class name for instances). |
str(x) |
Display-string form of a value. |
repr(x) |
Debug form (strings come back quoted). |
num(x) |
Parse a number from a string / bool / number. |
int(x) |
Truncate a number (or parsed string) toward zero. |
bool(x) |
Truthiness of a value. |
Math
| Function | Description |
|---|---|
abs(n) |
Absolute value. |
floor(n) / ceil(n) / round(n) |
Round down / up / nearest. |
sqrt(n) |
Square root. |
pow(base, exp) |
Exponentiation. |
min(a, b, ...) / min(list) |
Smallest number. |
max(a, b, ...) / max(list) |
Largest number. |
range(stop) / range(start, stop[, step]) |
Build a list of numbers. |
Collections
| Function | Description |
|---|---|
push(list, x) |
Append x; returns the list. |
pop(list) |
Remove and return the last element. |
keys(dict) |
List of keys. |
values(dict) |
List of values. |
Misc
| Function | Description |
|---|---|
ord(s) |
Character code of the first character. |
chr(n) |
One-character string for code point n. |
assert(cond[, message]) |
Raise a runtime error if cond is falsey. |