3.3.5
Operator precedence (3.3.5) is a Class 10 Computer Science lesson for the Punjab boards. It walks through the idea in plain steps, then sets a short check, in English, Urdu or Roman Urdu.
Your guide: Miss HiraExplains computers with chai, cricket and your phone.
Chapter 1 of every subject is free. Unlock every chapter of this class with the full course.
Unlock full courseAlready paid? Sign in with the Google account you paid with.
Precedence is the order Python evaluates operators. Highest first: parentheses (), then exponent **, then * / // %, then + and −. Equal-precedence operators go left to right, except ** which goes right to left.
(3 + 2) * 4 = 20, but 3 + 2 * 5 = 13. In 4 * 3 + 10 / 2 − 11 % 3, Python finds 12, 5.0 and 2 first, then 12 + 5.0 − 2 = 15.0.
Book note: the book prints 2 + 2 * 2 ** 3 = 32. Python gives 18, because 2 ** 3 = 8, then 2 * 8 = 16, then 2 + 16 = 18.
Step 1 / 1
Precedence is the order Python evaluates operators. Highest first: parentheses (), then exponent **, then * / // %, then + and −. Equal-precedence operators go left to right, except ** which goes right to left.
(3 + 2) * 4 = 20, but 3 + 2 * 5 = 13. In 4 * 3 + 10 / 2 − 11 % 3, Python finds 12, 5.0 and 2 first, then 12 + 5.0 − 2 = 15.0.
Book note: the book prints 2 + 2 * 2 ** 3 = 32. Python gives 18, because 2 ** 3 = 8, then 2 * 8 = 16, then 2 + 16 = 18.
Brackets → powers → * / // % → + −, left to right within a level.
Found a mistake? Tell us the lesson and the line at exciting@boringeducation.com.
No ads. Tell us what to fix.