In python, the number data types are used to store numeric values.
Python supports three numeric data types:
- int – negative and non-negative numbers having no decimal point
- float – used to store decimal point value
- Complex – It is of the form a + bj in which a is the real part and the in bj j j is the imaginary one.
Let’s understand one by one with the examples:
- int: they are whole numbers, the negative and non-negative numbers having no decimal point. There is no limit to integers in Python.
Python Numbers With Examples
type(): it is a function through which we specify the type of the object, whether it is int, float, or double.
Float: used to store floating point numbers or decimal point numbers, it helps in storing the result which has decimal point number like 4.34, 4.56788.
Divide a number by a number produces a float
1.909836065573770 has many digits after decimal so,
Note: accuracy of the float point number is up to 15 decimal places.
Float is produced by multiplication by multiplying two float numbers,
- Complex: The complex number consists of two parts the real and the imaginary one.
3 + 4j
The 3 is the real component and 4j is the imaginary one(j is the imaginary part)
Random Number in Python:
Python has a built-in module which is known as random which is used to generate random numbers.
For using built-in modules we have to import the modules through import.
import module name
we will use randrange() method which returns a randomly selected element from the given range.Let’s understand this by the example