Skip to content

Expression Functions -- Auto-Generated

Info

This page is auto-generated from the safe_eval() function in syntax.py at build time. It cannot go stale.

These functions and constants are available in variable expressions, calc, if, while, assert, check, and pyeval.

Type Conversions

Function Description
int(x) Convert to integer
float(x) Convert to float
str(x) Convert to string
bool(x) Convert to boolean
hex(x) Integer to hex string
bin(x) Integer to binary string
oct(x) Integer to octal string
ord(c) Character to Unicode code point
chr(n) Unicode code point to character

Math Basics

Function Description
abs(x) Absolute value
round(x [, n]) Round to n decimal places
min(a, b, ...) Minimum value
max(a, b, ...) Maximum value
sum(iterable) Sum of elements
pow(x, y) x raised to power y
divmod(a, b) Quotient and remainder
len(x) Length of sequence

Math Module

Function Description
sqrt(x) Square root
log(x) Natural logarithm
log2(x) Base-2 logarithm
log10(x) Base-10 logarithm
exp(x) e raised to power x
ceil(x) Round up to nearest integer
floor(x) Round down to nearest integer
hypot(x, y) Euclidean distance: sqrt(xx + yy)

Trigonometry

Function Description
sin(x) Sine (radians)
cos(x) Cosine (radians)
tan(x) Tangent (radians)
asin(x) Inverse sine
acos(x) Inverse cosine
atan(x) Inverse tangent
atan2(y, x) Two-argument inverse tangent
degrees(x) Radians to degrees
radians(x) Degrees to radians

NaN / Infinity Checks

Function Description
is_nan(x) True if x is NaN
is_inf(x) True if x is infinite
is_finite(x) True if x is finite (not NaN or inf)

Constants

Name Value
pi 3.141592653589793
e 2.718281828459045
inf Positive infinity
nan Not a number
true / True Boolean true
false / False Boolean false

Operators

Operator Meaning
+ - * / // ** % Arithmetic
\| & ^ << >> Bitwise (operands cast to int)
+ - not ~ Unary
== != < <= > >= Comparison
and or not Boolean (short-circuit)
&& \|\| Aliases for and / or
a if cond else b Ternary
[a, b, c] List literal
x[i] Subscript

Special Behaviors

  • Division by zero returns nan (not an error)
  • Attribute access (obj.attr) is not allowed
  • Unknown names are treated as string literals (e.g., status == passed compares against the string "passed")
  • ^ is rewritten to ** -- use ^ for exponentiation, not bitwise XOR