All courses › Programming with Python › Numbers and types

Numbers and types

Python has several kinds of numbers. int is a whole number, float a decimal number. Regular division / always gives a float, while // rounds down to an integer and % gives the remainder. type(x) shows a value's type.

a / ba\,/\,bregular division, always float
a / ⁣/ ba\,/\!/\,binteger division, rounded down
a%ba \% bremainder after integer division

Symbols

a, ba,\ bthe numbers being divided

Example

7 // 2 gives 3, and 7 % 2 gives 1, since 7=3⋅2+17 = 3\cdot 2 + 1.

7 / 2 gives 3.5.

// and % are linked: a == (a // b) * b + a % b.
Practise python basics for free →

Strings and indexing →

Part of Programming with Python: Python basics.