Number Data Type





In Python, numbers are represented by three distinct types:

  • integers (int),
  • floating-point numbers (float),
  • complex numbers (complex).

Integers (int) : are whole numbers (positive, negative or zero) without any decimal point. For example, 5, -10, and 0 are all integers in Python.

Floating-point numbers (float) : represent real numbers with decimal points or scientific notation. For example, 3.14, 2.0, and -0.1 are all floating-point numbers in Python.

Complex numbers (complex) : are numbers that have a real part and an imaginary part, both represented as floating-point numbers. Complex numbers are represented in Python using the j suffix, for example, 3 + 4j is a complex number with a real part of 3 and an imaginary part of 4.


Here are some examples of using these data types in Python:

x = 5 # integer
y = 3.14 # floating-point number
z = 2 + 3j # complex number
You can perform mathematical operations such as addition, subtraction, multiplication, and division on numbers in Python using arithmetic operators (+, -, *, /) and others.


Here are the built-in functions for Number data type in Python:

FunctionExplanation
abs(x) Returns the absolute value of a number.
pow(x, y) Returns the value of x to the power of y.
round(x, n) Rounds a number to n decimal places.
max(iterable) Returns the largest item in an iterable or the largest of two or more arguments.
min(iterable) Returns the smallest item in an iterable or the smallest of two or more arguments.
sum(iterable) Returns the sum of all items in an iterable.
int(x) Converts x to an integer.
float(x) Converts x to a floating-point number.
complex(real, imag) Returns a complex number with the value real + imag*j.
divmod(x, y) Returns the quotient and remainder of x divided by y.
hex(x) Converts an integer to a lowercase hexadecimal string.
oct(x) Converts an integer to an octal string.
bin(x) Converts an integer to a binary string.
abs() Returns the absolute value of a number.
pow() Returns the value of x to the power of y.
round() Rounds a number to the nearest integer.
floor() Returns the largest integer less than or equal to a number.
ceil() Returns the smallest integer greater than or equal to a number.
sqrt() Returns the square root of a number.
log() Returns the natural logarithm of a number.
log10() Returns the base-10 logarithm of a number.
exp() Returns e raised to the power of x.
Note: Some of these functions have additional parameters or variants, please refer to Python documentation for more information.