11. Expressions

The following logical operators yield bool values:

Number of Operands Operator Description
binary and,or Logical "and" and "or".
unary not Logical "not".

The "not" operator has a higher precedence than the "and" and "or" operators.

The following relational operators yield bool values: ==, !=, <, <=, >, >=. The operands may be of any type. Operands of type bool and int are converted to type float. Values of type str are always "greater" than bool and numeric values. Relational operators have higher precedence than logical operators.

The following arithmetic operators (for expressions of type int and float) are available. They are listed with increasing precedence (all of them with higher precedence than relational operators), with the addition and subtraction operators having the lowest precedence, and the power operator the highest.

Number of Operands Operator Description
binary +,- Addition and subtraction.
binary *,/,mod Multiplication, division, and modulus.
unary +,- Defines the sign of the numeric operand.
binary ** Power.

All these operators can be applied to operands of type int and type float. For binary operators, when both operands are of type int, the result is also of type int. When both operands are of type float, the result is also of type float. When one operand is of type int and the other of type float, the int operand is first converted to a float, and the result is of type float.

For str expressions, the binary operator + means concatenation:

("A " + "string " + "with " + "several " + "words.")

Sub-expressions may be enclosed in parentheses to override the operator precedence rules. Example:

(e=73.1e3) (p=0.33) (g=e/(2*(1+p)) (g)