Python Tutorials
Basic

Data Structure and Data Types

String

List

Tuple

Set

Dictionary

Functions / Methods

Advance

Exception Handling

Python Numbers


Numbers

In Python, there are three numeric data types.

Int, Float, Complex

Example
number_int = 100
number_float = 100.111
number_complex = 100j

print(number_int)
print(number_float)
print(number_complex)
100
100.111
100j

Python Integer Number

Int - Int or integer is a whole positive or negative number without a decimal point. The length of an integer number is unlimited.

Example
number_a = 100
number_b = 123123451234561234567
number_c = -12312345

print(number_a)
print(number_b)
print(number_c)
100
123123451234561234567
-12312345

Python Float Number

Float - A float is either a positive or a negative decimal point number.

Example
number_a = 100.111
number_b = 100.0
number_c = -100.222

print(number_a)
print(number_b)
print(number_c)
100.111
100.0
-100.222

There is also the possibility of floating numbers with an "e" to indicate a power of 10.

Example
number_a = 80E2
number_b = 10e3
number_c = -55.8e3

print(number_a)
print(number_b)
print(number_c)
8000.0
10000.0
-55800.0

Python Complex Number

Complex - The complex number in Python is always written as a numeric value with a "j" text character.

In this case, the numeric value is the real part, and the number with the character "j" is the imaginary part.

Example
number_a = 1+7j
number_b = 7j
number_c = -10j

print(number_a)
print(number_b)
print(number_c)
(1+7j)
7j
(-0-10j)

Example
number_a = 1+7j
number_b = 7j
number_c = -10j

print(type(number_a))
print(type(number_b))
print(type(number_c))
<'class' 'complex'>
<'class' 'complex'>
<'class' 'complex'>

Example
number_int = 100
number_float = 100.111
number_complex = 100j

number_a = float(number_int)
number_b = int(number_float)
number_c = complex(number_int)

print(number_a)
print(number_b)
print(number_c)

print(type(number_a))
print(type(number_b))
print(type(number_c))
100.0
100
(100+0j)
<'class' 'float'>
<'class' 'int'>
<'class' 'complex'>