Level 1
0 / 100 XP

What is a float?

Not every number is a whole number. Prices, measurements, percentages, coordinates — the real world is full of decimals. Python handles these with floats.

What is a float?

A float is any number with a decimal point:

Python
price = 9.99 height = 1.75 temperature = -3.5 percentage = 98.6 print(price) print(height) print(temperature) print(percentage)

The name comes from "floating point" — a reference to how the decimal point can appear anywhere in the number.

Floats can look like whole numbers

A number doesn't have to have digits after the decimal to be a float — the decimal point alone is enough:

Python
a = 5 b = 5.0 print(a) # 5 print(b) # 5.0

Same value, different type. Python treats these differently — and that will matter soon.

Floats are not always exact

Unlike integers, floats can have tiny rounding errors. This is a quirk of how computers store decimal numbers:

Python
print(0.1 + 0.2) # 0.30000000000000004

That's not a Python bug — it's how floating point arithmetic works on every computer. For most programs it doesn't matter, but it's worth knowing it exists.

Key takeaways

  • A float is any number with a decimal point
  • 5 and 5.0 look similar but Python treats them as different types
  • Floats can have tiny rounding errors — this is normal and expected