Python gave me 16. I expected 36.
Here’s why — and why it matters for your code.
Python has 6 types of operators. Most tutorials teach you 2.
① Arithmetic — +, -, *, /, //, %, **
The ones beginners miss: // (floor division) and % (remainder/modulus)
② Comparison — ==, !=, >, <, >=, <=
All return True or False. Power every if statement and Pandas filter.
③ Logical — and, or, not
df[(df[‘age’] > 18) & (df[‘score’] > 50)] ← two conditions, one line
④ Assignment — +=, -=, *=, /=
Stop writing a = a + 5. Just write a += 5.
⑤ Membership — in, not in
‘Delhi’ in cities → True. Check membership in one word.
⑥ Identity — is, is not
a == b → True (same values)
a is b → False (different objects in memory)
These are not the same thing.
Now — why 10 + 2 * 3 = 16:
Python follows PEMDAS. Multiplication first: 2*3=6, then 10+6=16.
Want 36? → (10 + 2) * 3
Parentheses always go first. Always.
Day 10 of learning Python for data science — documenting every concept.
Which operator did you not kno...
Suggested Credits
Tags, Events, and Projects