GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Python Tutorial
  • Data Types
  • Interview Questions
  • Examples
  • Quizzes
  • DSA Python
  • Data Science
  • NumPy
  • Pandas
  • Practice
  • Django
  • Flask
  • Introduction1 min read
  • Input & Output2 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — Python Numbers - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • Python Tutorial
  • Data Types
  • Interview Questions
  • Examples
  • Quizzes
  • DSA Python
  • Data Science
  • NumPy
  • Pandas
  • Practice
  • Django
  • Flask

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.

Python
a = 4
b = 4.5
c = 4j 
print(type(a))
print(type(b))
print(type(c))

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.

Python
x = 5      # Positive integer
y = -23    # Negative integer
z = 0      # Zero

Arithmetic Operations on Integers

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

Python
print(5 + 3)
print(10 - 4)
print(7 * 6)
print(15 / 4)
print(15 % 4)
print(2 ** 3)
print(abs(-10))
print(round(3.14159, 2))

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.

Python
a = 3.14      # Positive float
b = -0.99     # Negative float
c = 0.0       # Float value representing zero

Arithmetic Operations on Float

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

Python
print(3.5 + 2.2)
print(7.8 - 4.3)
print(5.5 * 2.0)
print(9.0 / 4.5)
print(9.0 // 4.5)
print(9.0 % 4.5)
print(2.5 ** 2)
print(abs(-7.4))
print(round(3.14159, 2))

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.

Python
print((3 + 4j) + (1 + 2j))
print((5 + 6j) - (2 + 3j))
print((2 + 3j) * (1 + 4j))
print((8 + 6j) / (2 + 3j))
print((1 + 1j) ** 2)
print(abs(3 + 4j))
print((3 + 4j).conjugate())
print((3 + 4j).real)
print((3 + 4j).imag)

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.
Python
import random

print(random.randint(1, 100))
print(random.uniform(1.0, 10.0))

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.
Python
import math

print(math.nan)
print(float('inf'))
print(float('-inf'))

Output
nan
inf
-inf
Comment

Explore

    Python Fundamentals
    • Introduction1 min read
    • Input & Output2 min read
    • Variables4 min read
    • Operators4 min read
    • Keywords2 min read
    • Data Types4 min read
    • Conditional Statements3 min read
    • Loops3 min read
    • Functions4 min read
    Python Data Structures
    • String4 min read
    • List3 min read
    • Tuples3 min read
    • Dictionary3 min read
    • Set2 min read
    • Arrays5 min read
    Advanced Python
    • OOP Concepts3 min read
    • Exception Handling5 min read
    • File Handling4 min read
    • Python Database2 min read
    • MongoDB3 min read
    • MySQL7 min read
    • Packages4 min read
    • Modules3 min read
    • DSA Libraries5 min read
    • Python GUI2 min read
    Data Science with Python
    • Numpy3 min read
    • Pandas4 min read
    • Matplotlib3 min read
    • Seaborn3 min read
    • StatsModel2 min read
    • Model Building6 min read
    • TensorFlow2 min read
    • PyTorch5 min read
    Web Development with Python
    • Flask3 min read
    • Django5 min read
    • Django ORM4 min read
    • Jinja2 Templating5 min read
    • Django Templates5 min read
    • REST API3 min read
    • Build API with DRF4 min read
    Python Practice
    • Quiz1 min read
    • Practice Problems2 min read
    • Interview Q & A15+ min read
    Courses
    • Placement 360 Course2 min read
    • Data Science 360 Course2 min read
    • AI Engg Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.