Python Numbers
Learn all about Python Numbers in this comprehensive tutorial.
- •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:
To verify the type of any object in Python, use the type() function:
Int
Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.
Float
Float, or "floating point number" is a number, positive or negative, containing one or more decimals.
Float can also be scientific numbers with an "e" to indicate the power of 10.
Complex
Complex numbers are written with a "j" as the imaginary part:
Type Conversion
You can convert from one type to another with the int(), float(), and complex() methods:
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:
In our Random Module Reference you will learn more about the Random module.
Module quiz
2 questionsWhich of the following is true about Python Numbers?
What is the most common pitfall when working with Python Numbers?
Answer all questions to submit.