# Parentheses and operator precedence

In general an expression may be enclosed in parentheses without changing its meaning.

If parentheses are not used, operator precedence follows the sequence below, starting with the operators that bind most tightly. Within each group the operators are evaluated left-to-right

Operator | Meaning
[] | predicate
/, // | path operator
unary -, unary + | unary plus and minus
cast as | dynamic type conversion
castable as | type test
treat as | static type conversion
instance of | type test
except, intersect | set difference and intersection
|, union | union operation on sets
*, div, idiv, mod | multiply, divide, integer divide, modulo
+, - | plus, minus
to | range expression
=, !=, is, isnot, <, <=;, >, >=, eq, ne, lt, le, gt, ge | comparisons
and | Boolean and
or | Boolean or
if | conditional expressions
some, every | quantified expressions
for | iteration (mapping) over a sequence
, (comma) | Sequence concatenation

The various operators are described, in roughly the above order, in the sections that follow.

Expand | Next