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.  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

There are various Numeric data types in Python. We can easily understand different types of Numeric data types using below image:

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

Operations on Int Data-Type in Python

Run
#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 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

Run
#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 one of the Numeric data-type in 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.

Operations on Complex Numbers in Python

Run
#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)

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription