What Is a Float in Python?

A float in Python is a number that can include a decimal point. Beginners often use floats for values like 3.14, 2.5, or -0.75.

Floats are useful when you need numbers that are not just whole numbers. For example, you might use them for measurements, prices in simple examples, or division results.

This page explains what the term float means, how it looks in Python, and how it differs from an integer.

Definition

A float is a numeric type in Python used for numbers with decimal values.

Examples:

  • 3.14
  • 2.5
  • -0.75
  • 5.0

Even though 5.0 looks like a whole number, Python still treats it as a float because it has a decimal point.

If you want to compare floats with whole numbers, see what is an integer in Python.

How floats look in Python

Floats usually appear with a decimal point.

Common examples:

  • 1.5
  • 0.0
  • -3.2

A decimal point usually means the value is a float.

Python also supports scientific notation. This also creates a float:

x = 1e3
print(x)
print(type(x))

Output:

1000.0
<class 'float'>

You can check a value's type with type():

print(type(3.14))
print(type(5.0))
print(type(5))

Output:

<class 'float'>
<class 'float'>
<class 'int'>

When beginners use floats

Beginners often use floats in situations like these:

  • Measurements such as height, weight, or distance
  • Money examples in simple lessons
  • Division results
  • User input converted with float()

Example:

height = 1.75
price = 4.99
result = 7 / 2

print(height)
print(price)
print(result)

Output:

1.75
4.99
3.5

A useful beginner rule is this:

  • / returns a float in Python

If you want a wider overview of number types, see Python numbers explained: int, float, complex.

Float vs int

An int stores whole numbers:

  • 1
  • 25
  • -7

A float stores numbers with decimal values:

  • 1.0
  • 25.5
  • -7.25

These two values are not the same type:

  • 5int
  • 5.0float

Example:

print(type(5))
print(type(5.0))
print(5 == 5.0)

Output:

<class 'int'>
<class 'float'>
True

So 5 and 5.0 can be equal in value, but they are different types.

Python can also do math with ints and floats together:

total = 2 + 3.5
print(total)
print(type(total))

Output:

5.5
<class 'float'>

Simple example

Here is a very small example of a float stored in a variable:

temperature = 21.5

print(temperature)
print(type(temperature))

Output:

21.5
<class 'float'>

What this does:

  • temperature = 21.5 stores a float in a variable
  • print(temperature) shows the value
  • print(type(temperature)) shows that the type is float

Important beginner note about precision

Floats are very useful, but they are not always perfectly exact.

Some decimal values cannot be stored exactly in binary form. Because of that, you may sometimes see small unexpected results.

Example:

print(0.1 + 0.2)

Output:

0.30000000000000004

This does not mean Python is broken. It means floats have small precision limits.

For beginner code, a practical fix is often to format or round the result:

print(round(0.1 + 0.2, 2))

Output:

0.3

You can learn more on the round() function.

Converting values to float

You can use float() to convert other values into floats.

Examples:

print(float("3.5"))
print(float(7))

Output:

3.5
7.0

This is common when working with user input:

user_text = "8.25"
number = float(user_text)

print(number)
print(type(number))

Output:

8.25
<class 'float'>

If the text is not a valid number, Python raises a ValueError:

float("hello")

Error:

ValueError: could not convert string to float: 'hello'

If you need help with that, see ValueError: could not convert string to float or how to convert a string to float in Python.

Common mistakes

Beginners often run into these problems:

  • Thinking every number is an int
  • Assuming 5 and 5.0 are the same type
  • Expecting decimal math to always be perfectly exact
  • Trying to convert non-number text with float()

Useful checks:

print(type(3.14))
print(type(5.0))
print(float("3.5"))
print(0.1 + 0.2)
print(round(0.1 + 0.2, 2))

These small tests help you quickly see:

  • whether a value is a float
  • how conversion works
  • how precision can affect output

FAQ

Is 5 a float in Python?

No. 5 is an int. 5.0 is a float.

Is 5.0 the same as 5?

They can compare as equal in value, but they are different types: float and int.

How do I create a float in Python?

Write a number with a decimal point, like 2.5, or convert a value with float().

Why does 0.1 + 0.2 give a strange result?

Floats cannot store some decimal values exactly, so small precision differences can appear.

Can I convert a string to a float?

Yes. Use float("3.14"). If the text is not a valid number, Python raises a ValueError.

See also