Zum Inhalt springen
KodeTrail

Camp 2 · Schritt 6 von 23

Numbers and math

Integers, decimals, and every operator you need — including the two division surprises.

12 Min.+50 XPAuf Englisch angezeigt — Übersetzung ist unterwegs

Python is a world-class calculator. Two kinds of numbers do almost all the work:

  • Integers (int) — whole numbers: 42, -3, 0
  • Floats (float) — numbers with a decimal point: 3.14, -0.5, 2.0

The operators

Python

Most are familiar, but three deserve a closer look:

OperatorName7 ? 3 givesUse it for
/division2.3333…exact division (always a float!)
//floor division2"how many whole times does it fit?"
%modulo1"what's left over?"

Modulo looks weird but shows up everywhere: minutes % 60, checking even/odd with n % 2, wrapping around a schedule with day % 7.

Order of operations

Python follows the math you learned in school — * and / before + and - — and parentheses override everything:

Python
Checkpoint

What is 10 % 3 in Python?

Checkpoint

What type of number does 8 / 2 produce?

What's next

Numbers, handled. Next: strings — working with text, from gluing words together to Python's superpower, the f-string.