7) Numbers and Math Lesson

Python Float and Python Integer

4 min to complete · By Martin Breuss

The numbers that you have encountered in the previous section may have felt familiar. You might call both 1 and 2.5 numbers---but Python is a little more specific than that! The two most important kinds of numbers that Python uses are:

  • Integers: Whole numbers without a decimal point, such as 1
  • Floating-Point Numbers: Decimal numbers, such as 1.23

While they are quite similar to each other, they are represented as different data types in Python. You'll look at each of them in this lesson.

Python Integers

Integers in Python have the type int. They are whole numbers, which means they don't have a decimal point.

Example

Here are a few integers as an example:

1
2
42
123456789
0

Any of these numbers are of the type int. Go ahead and test their types in your Python interpreter! You can also practice assigning them to a variable, then use type() on the variable name instead.

Colorful illustration of a light bulb

Note: As soon as you use a decimal point, it's not an int anymore. That holds true even if the only numbers following the decimal point are zeroes, e.g., 1.00

Integers are what you might think of as just normal numbers. Another type of number that you are familiar with from everyday maths is decimal numbers, which in Python are of a different data type than integers.

Python Float

Floating-point numbers, also often called floats for short, are numbers with fractions. That means that any number that contains a decimal point is of the type float in Python.

Example

Here are a few floats as an example:

1.0
123.45
9.99
0.5
0.0

Type Checking Practice

In Python, ints and floats behave quite similarly in many ways, even though they are of different data types. Go ahead and check the types of some floats in your Python interpreter or the playground below:

# Check the type of some int and floats below

You might think that it could be fun to build a calculator using Python! So, instead of just looking at these numbers and checking their type, you could do some math with them. Good call and keep up the spirit, but there's no need to build anything for that. Python already is a calculator. You'll explore this some more in the upcoming lesson.

Summary: Python Float and Python Integer

  • Floats and integers are Python two main number data types
  • Floats (float): Decimal numbers, such as 1.23
  • Integers (int): Whole numbers without a decimal point, such as 1