Python Tutorials · Python Numbers

Python Numbers

Learn all about Python Numbers in this comprehensive tutorial.

5 min read beginner
  • There are three numeric types in Python:
  • Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.
  • Float, or "floating point number" is a number, positive or negative, containing one or more decimals.
  • Complex numbers are written with a "j" as the imaginary part:
  • You can convert from one type to another with the int(), float(), and complex() methods:
  • Python does not have a random() function to make a random number, but Python has a built-in module called random that can be used to make random numbers:

Python Numbers

There are three numeric types in Python:

  • int
  • float
  • complex

Variables of numeric types are created when you assign a value to them:

python

To verify the type of any object in Python, use the type() function:

python

Int

Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.

python

Float

Float, or "floating point number" is a number, positive or negative, containing one or more decimals.

python

Float can also be scientific numbers with an "e" to indicate the power of 10.

python

Complex

Complex numbers are written with a "j" as the imaginary part:

python

Type Conversion

You can convert from one type to another with the int(), float(), and complex() methods:

python
Note: Note: You cannot convert complex numbers into another number type.

Random Number

Python does not have a random() function to make a random number, but Python has a built-in module called random that can be used to make random numbers:

python

In our Random Module Reference you will learn more about the Random module.

Module quiz

2 questions
1

Which of the following is true about Python Numbers?

2

What is the most common pitfall when working with Python Numbers?

Answer all questions to submit.