operator precedence
The rules that decide which operators in an expression are applied first, such as multiplication before addition.
In more detail
Most languages follow the usual maths order for arithmetic, then apply comparisons, then logical operators, with and binding tighter than or. Parentheses override the default order, so an expression written without them can mean something other than it reads. Adding parentheses for clarity is always allowed, and is wise whenever a condition mixes and with or.
Examples
2 + 3 * 4 # 14(2 + 3) * 4 # 20WHERE (category_id = 1 OR category_id = 2) AND price_cents < 4000Related terms
- arithmetic operator — A symbol that does arithmetic on numbers: + add, - subtract, * multiply, / divide, // floor divide, % remainder and ** power.
- expression — A piece of code that Python can evaluate to produce a value, such as 2 + 3, name or len(word).
- comparison operator — An operator that compares two values and gives true or false, such as equal, not equal, less than or greater than.
- logical operator — An operator such as AND, OR or NOT that combines or reverses true-or-false conditions.
- WHERE clause — The part of a query that keeps only the rows for which a condition is true.
Taught in
- Integer Arithmetic And Precedence — Hands-on Python: Complete Video Course & Book
- Exponents, Roots And Float Formats — Hands-on Python: Complete Video Course & Book
- Chapter One In One Sitting — Hands-on Python: Complete Video Course & Book
- Objects, Methods And String Case — Hands-on Python: Complete Video Course & Book
- Filtering With The WHERE Clause — PostgreSQL, Indexing & Relational Data Modeling
- Literals, Names And Four Number Bases — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Operators And Who Binds First — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Fundamentals Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Twelve Traps, One Shape Each — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep