For example, the traditional mathematical order of operations is:
- Parentheses (sometimes also called Brackets)
Those operators all exist in programming as well, as well as a few additional ones:
|Parentheses||Anything inside |
|Exponents||Things like x2. Written as x**2 in code.|
|Negation||Negative numbers like |
|Multiplication, Division, Remainder||Multiplication is represented by |
|Addition and Subtraction|
|Comparisons, such as identity and membership tests.|
|As in, |
This table is not exhaustive; for the full list, see the Python documentation. That said, it’s doubtful you’ll end up using some of the operators I excluded from the table above in a visual novel game, such as bitwise AND or shifts.
In short, order of operations lets us know which order we should evaluate a statement like the following:
2 + 3 * 4 -> multiplication comes before addition, so we do
3*4 first and end up with
2 + 12 = 14. Without following order of operations, we could have ended up with a different answer like 20.
Ren’Py always follows order of operations when determining the result of an expression, so you should be sure to know what order your operators are being evaluated in so your conditional statement does what you’re expecting.« Back to Glossary Index