Atom

Operator precedence

Choose which operation should happen first

Atom groups multiplication before addition. Parentheses change the grouping.

Atom
print(2 + 3 * 4)
print((2 + 3) * 4)
Output
14
20

The first calculation adds 2 to 12. The second multiplies 5 by 4.

This table lists precedence from lowest to highest. Postfix expressions bind most tightly.

Precedence Operators Associativity
1 ?? Right
2 or Left
3 and Left
3½ Prefix not Prefix, operand starts at level 4
4 == != Left
5 < <= > >= Left
6 | Left
7 ^ Left
8 & Left
9 << >> Left
10 .. Left
11 + - Left
12 * / % Left
13 Unary + - ~ Prefix
14 ** Right
15 Calls, indexing, member access, optional member access Left