Python Tutorial

What are Python Numbers? int, float, complex

What are Numbers in Python?

Integers, floating-point numbers, and complex numbers are all supported in Python. In Python, they are known as int, float, and complex classes. 

The presence of a decimal point distinguishes integers from floating points. For example, the number 5 is an integer, but the number 5.0 is a floating-point number. 

The formula for complex numbers is x + yj, where x is the real component and y is the imaginary part.

Int

The int class represents this value. It comprises full numbers that are either positive or negative (without fraction or decimal). There is no limit on how lengthy an integer value can be in Python.

Float

The float class is used to represent this value. It's a floating-point representation of a real number. A decimal point is used to denote it. To designate scientific notation, the characters e or E, followed by a positive or negative number, might be inserted.

Complex

The float class is used to represent this value. It's a floating-point representation of a real number. A decimal point is used to denote it. To designate scientific notation, the characters e or E, followed by a positive or negative number, can be inserted.

Example:

# Python program to 

# demonstrate numeric value

a = 9

print("Type of a: ", type(a))

b = 9.0

print("\nType of b: ", type(b))  

c = 9 + 2j

print("\nType of c: ", type(c))

Output:

Type of a:  <class 'int'>
Type of b:  <class 'float'>
Type of c:  <class 'complex'>
Did you find this article helpful?