L1·Foundations

🔢Numbers & Operators

Arithmetic, integer vs float division, modulo.

mathintfloat//%**

§ 1Operators

+ - * / // % ** — plus, minus, times, true divide, floor divide, modulo, power.

§ 2True vs floor division

/ always returns float. // truncates toward negative infinity.

§ 3Precedence

** > unary - > * / // % > + -. Use parentheses when in doubt.

Example

1print(7 / 2) # 3.5
2print(7 // 2) # 3
3print(7 % 2) # 1
4print(2 ** 10) # 1024
5print(-7 // 2) # -4 (floor!)

Try it live · Python runs in your browser

Loading playground…

Checkpoint quiz

Question 1 / 3
What is 10 // 3?