Arithmetic Operators
Arithmetic operators do number work.
They are the same ideas as school math.
Add toys. Share cookies. Count leftovers.
Python writes them with short signs.
Add and subtract
+ adds. - subtracts.
You can use numbers or variables.
Multiply and divide
* multiplies. / divides.
Division with / always gives a float.
Floor divide and remainder
// divides and keeps the whole part.
% gives the leftover.
Like sharing 10 cookies with 3 kids. Each gets 3. One cookie is left.
Powers
** means raised to a power.
2 ** 3 means 2 times 2 times 2.
Shortcuts that update a variable
These change a variable and put the answer back in the same drawer.
+= add to me
-= subtract from me
*= multiply me
/= divide me
//= floor-divide me
%= keep my leftover
**= raise me to a power
Parentheses for clarity
Use parentheses when the order could confuse a reader.
Clear order beats clever order.
Tip: Remember / gives a float. Use // when you want whole shares only.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.