Numeric data-type in Python programming language

Numeric data-type in Python programming language

Data-types in python

Numeric data-type in Python programming language is used to store the numeric values in any variable. Numeric data-type is used in many areas of operation. To perform some numeric operations or calculations numeric data type is used to store the values. The numeric data type is divided into three parts:

  • Integer
  • Float
  • Complex Number

All the above sub-parts of a numeric datatype are used in different places for a different operation.

Different data-types in python

Data-types in python

Int Data-type in Python :

Integer data-types are used to perform some real number operations. Mostly int values are used in iterating through the loop and getting item indexes in the data structure. Integers do not contain decimal point values, even if we try to save a decimal value to the integer data-type, it will automatically remove the decimal point values an stores the integer part of the value

Int data-type in python

Operations on Int data-type in Python

#Integer inputs
Var = int(input('Enter an integer value: '))
print(Var)


#using int in loops
#initialize an integer
i = 0
while i <= 4:
    print(i,end=" ")
    i+=1
print()


#using int to iterate through an list
#initialize a list
arr = [1,2,3,4,5]
#iterating through list
for integer in range(len(arr)):
    print(arr[integer],end=" ")
print()

#mathematical operations on integer
#initialize int variables
a = 10
b = 2
#addition
print(a+b)


#Subtraction
print(a-b)


#multiplication
print(a*b)


#division
print(a/b)


#floor division
print(a//b)
Output:
Enter an integer value: 10
0 1 2 3 4
1 2 3 4 5
12
8
20
5.0
5

Float data-type in Python :

float in python

Float data-types are used to store the decimal numbers. Float data-types stores the numeric values written after the decimal point. We can use format in-built function to store or print the values after decimals according to our need. Float data-types are used to calculate the exact mathematical outputs up to some decimal points.

Operations on Float data-type in Python

#Float inputs
Var = float(input('Enter an float value: '))
print(Var)


#mathematical operations on Float
#initialize float variables
a = 10.12
b = 2.11
#addition
print(a+b)


#Subtraction
print(a-b)


#multiplication
print(a*b)


#division
print(a/b)


#floor division
print(a//b)
Output:
Enter an float value: 10
10.0
12.229999999999999
8.01
21.353199999999998
4.796208530805687
4.0

Complex numbers in Python :

Complex numbers are the data-types in the python programming language. Complex numbers are a combination of a real part and an imaginary part or imaginary value. The real part has the real number value and the imaginary part is usually represented by “j”, represented as- 2+7j. Complex numbers are used to perform some scientific and mathematical calculations.

Complex numbers in python

Operations on Complex numbers in Python

#Complex number inputs
Var = complex(input('Enter an complex number value: '))
print(Var)


#mathematical operations on complex number
#initialize complex number variables
a = 2+4j
b = 3+6j
#addition
print(a+b)


#Subtraction
print(a-b)


#multiplication
print(a*b)


#division
print(a/b)
Output:
Enter an complex number value: 10
(10+0j)
(5+10j)
(-1-2j)
(-18+24j)
(0.6666666666666666+0j)