Built-in Functions
| Function | Description |
|---|---|
assert(condition) | Panics if condition is falsy |
assert(condition, message) | Panics with message if condition is falsy |
panic(message) | Immediately halts execution with an error message |
dict() | Creates a new empty dictionary |
dict(key=value, ...) | Creates a dictionary with string keys from keyword names |
Range(start, end) | Creates a range from start (inclusive) to end (exclusive) |
enumerate(iterable) | Returns an iterable yielding (index, value) tuples |
filter(iterable) | Returns a list of truthy values from any iterable |
filter(iterable, fn) | Returns a list of values where fn(value) is truthy |
average(iterable) | Returns the arithmetic average, or 0 for an empty iterable |
bool(value) | Converts a value’s truthiness to a boolean |
str(value) | Converts a value to a string |
repr(value) | Converts a value to a string with an equivalent in source code (where possible) |
int(value) | Converts a value to an integer (panics on failure) |
float(value) | Converts a value to a float (panics on failure) |
try_int(value) | Converts a value to an integer, returns None on failure |
try_float(value) | Converts a value to a float, returns None on failure |
Type Conversion Examples
print(int("42"))
print(float("3.14"))
print(str(123))Press the play button to execute
The try_ variants return None instead of panicking on invalid input:
let good = try_int("42")
print(good)
let bad = try_int("hello")
print(bad)Press the play button to execute
Iterable Functions
Generic iterable helpers work with lists, ranges, strings, dictionaries, and custom iterators:
for i, value in enumerate(["a", "b"]) {
print(i, value)
}
print(filter([0, 1, "", "ok"]))
print(average([2, 4, 6]))
print(average([]))Press the play button to execute