Learn Python
>>> variables_data_types.numbers

Numbers: int, float, complex in Python

#concept

Python has three built-in numeric types: int for whole numbers of any size, float for decimal numbers, and complex for numbers with a real and imaginary part. Ints in Python can grow arbitrarily large without overflowing, unlike the fixed-size integers many other languages use.

Floats, on the other hand, are stored with limited precision — the same binary format nearly every language uses — which occasionally produces results that look slightly "off," like 0.1 + 0.2 not printing as exactly 0.3. That's a property of how decimals are represented in binary, not a Python quirk.

#how it works
1

int — whole numbers

Positive or negative, with no fixed size limit — Python grows the number as needed.

2

float — decimal numbers

Stored using the standard double-precision format most languages share.

3

Floating-point precision has limits

0.1 + 0.2 does not equal exactly 0.3, because most decimal fractions have no exact binary representation.

4

complex — real and imaginary parts

Written like 2+3j, used mainly in scientific and engineering calculations.

5

Mixing int and float promotes to float

5 + 2.5 automatically becomes 7.5, a float — Python never silently loses the decimal part.

#example
print(10 // 3)
print(10 / 3)
print(0.1 + 0.2)
print(2 ** 10)
Output
3
3.3333333333333335
0.30000000000000004
1024
1// is floor division — it discards the remainder, so 10 // 3 gives 3.
2/ is true division — it always returns a float, even when the numbers divide evenly.
30.1 + 0.2 does not print exactly 0.3, because floats are stored in binary and 0.1 has no exact binary representation — this happens in every mainstream language, not just Python.
4** is the exponent operator; 2 ** 10 computes 2 to the 10th power.
#use cases
Doing exact integer math for counting, indexing, and loop bounds, where floor division and modulo are common
Being aware of floating-point precision limits before comparing floats with ==, using rounding or a tolerance instead
Handling arbitrarily large integers — factorials, cryptography — without worrying about overflow
Complex numbers in scientific and engineering calculations, such as signal processing

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in Python yourself — building beats watching.