![]() |
VOOZH | about |
Numbers are used to store numeric values and perform mathematical operations such as addition, subtraction, multiplication and division. Python provides different numeric data types to work with whole numbers, decimal values and complex numbers.
<class 'int'> <class 'float'> <class 'complex'>
Python mainly supports the following number types:
An integer (int) represents whole numbers without decimal values. Integers can be positive, negative or zero. Python allows storing very large integer values without any fixed size limit.
Python supports different arithmetic operations on integer values such as addition, subtraction, multiplication and division.
8 6 42 3.75 3 8 10 3.14
A float (float) represents numbers with decimal values. Float numbers can be positive, negative or zero. They are commonly used when more precise numeric values are needed, such as measurements or calculations involving decimals.
Python supports different arithmetic operations on float values similar to integers.
5.7 3.5 11.0 2.0 2.0 0.0 6.25 7.4 3.14
Note: Float values are accurate up to about 15 decimal places. Beyond that, small precision differences may occur.
A complex number (complex) consists of two parts: Real part and Imaginary part. The imaginary part is represented using j. Complex numbers are commonly used in scientific and mathematical calculations.
a = 2 + 3j
Here, 2 is the real part and 3j is the imaginary part.
Python supports different arithmetic operations on complex numbers.
(4+6j) (3+3j) (-10+11j) (2.6153846153846154-0.9230769230769231j) 2j 5.0 (3-4j) 3.0 4.0
To know about Type Conversion, please refer to this article Type Conversion
Python provides the random module to generate random numbers. Random values are useful in applications such as games, simulations, password generation and testing.
29 3.8144379848390937
Note: Output may be different each time the program runs.
Python provides special numeric values that are used in scientific calculations and situations where normal numbers cannot represent a result.
nan inf -inf