VOOZH about

URL: https://www.geeksforgeeks.org/python/python-numbers/

⇱ Python Numbers - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python Numbers

Last Updated : 27 May, 2026

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.


Output
<class 'int'>
<class 'float'>
<class 'complex'>

Types of Numbers

Python mainly supports the following number types:

1. Integer

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.

Arithmetic Operations on Integers

Python supports different arithmetic operations on integer values such as addition, subtraction, multiplication and division.


Output
8
6
42
3.75
3
8
10
3.14

2. Float

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.

Arithmetic Operations on Float

Python supports different arithmetic operations on float values similar to integers.


Output
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.

3. Complex Numbers

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.

Arithmetic Operations on Complex Numbers

Python supports different arithmetic operations on complex numbers.


Output
(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

Random Numbers

Python provides the random module to generate random numbers. Random values are useful in applications such as games, simulations, password generation and testing.

  • random.randint(a, b) generates a random integer between a and b (both inclusive).
  • random.uniform(a, b) generates a random floating-point number between a and b.

Output
29
3.8144379848390937

Note: Output may be different each time the program runs.

Special Numbers

Python provides special numeric values that are used in scientific calculations and situations where normal numbers cannot represent a result.

  • NaN (Not a Number): Represents an undefined or invalid numeric result.
  • Infinity: Represented using float('inf'), used for values greater than any finite number.
  • Negative Infinity: Represented using float('-inf'), used for values smaller than any finite number.

Output
nan
inf
-inf
Comment
Article Tags: