Number information types store numeric qualities. They are permanent information types, which implies that changing the worth of a number information type brings about a recently designated object.
Various kinds of Number information types are :
int
float
complex
We should see every last one of them:
Int type
int (Integers) are the entire number, including negative numbers yet not portions. In Python, there is no restriction to how long an integer worth can be.
num = - 8
# print the information type
print(type(num))
Yield:
<class 'int'>
a = 5
b = 6
# Addition
c = a + b
print("Addition:",c)
d = 9
e = 6
# Subtraction
f = d - e
print("Subtraction:",f)
g = 8
h = 2
# Division
I = g/h
print("Division:",i)
j = 3
k = 5
# Multiplication
l = j * k
print("Multiplication:",l)
m = 25
n = 5
# Modulus
o = m % n
print("Modulus:",o)
p = 6
q = 2
# Exponent
r = p ** q
print("Exponent:",r)
Yield:
Expansion: 11
Deduction: 3
Division: 4.0
Duplication: 15
Modulus: 0
Example: 36
Read Our Latest Article: Scope of Variables in Python
Float type
This is a genuine number with floating-point portrayal. It is indicated by a decimal point. Alternatively, the person e or E followed by a positive or contrary integer might be attached to indicate logical documentation. . A few instances of numbers that are addressed as floats are 0.5 and - 7.823457.
They can be made straight by entering a number with a decimal point, or by using tasks like division on integers. Additional zeros present at the number's end are disregarded naturally.
num = 3/4
# print the information type
print(type(num))
Yield:
<class 'float'>
As we have seen, dividing any two integers creates a float.
A float is additionally delivered by running a procedure on two floats, or a float and an integer.
num = 6 * 7.0
print(type(num))
Yield:
<class 'float'>
Code block
Yield:
Expansion: 10.6
Deduction: 5.4
Division: 3.0769230769230766
Duplication: 20.8
Complex sort
A complex number is a number which comprises of the genuine and imaginary part. For instance, 2 + 3j is a complex number where 2 is the genuine segment, and 3 increased by j is an imaginary part.
num = 6 + 9j
print(type(num))
Yield:
<class 'complex'>
a = 1 + 5j
b = 2 + 3j
# Addition
c = a + b
print("Addition:",c)
d = 1 + 5j
e = 2 - 3j
# Subtraction
f = d - e
print("Subtraction:",f)
g = 1 + 5j
h = 2 + 3j
# Division
I = g/h
print("Division:",i)
j = 1 + 5j
k = 2 + 3j
# Multiplication
l = j * k
print("Multiplication:",l)
Yield:
Expansion: (3+8j)
Deduction: (- 1+8j)
Division: (1.307692307692308+0.5384615384615384j)
Duplication: (- 13+13j)
Type Conversion between numbers
We can change over one number into the other structure by two techniques:
Using Arithmetic Operations: We can utilize activities like expansion, deduction to change the sort of number implicitly(automatically), on the off chance that one of the operands is float. This technique isn't working for complex numbers.
a = 1.6
b = 5
c = a + b
print(c)
Yield:
6.6
Using worked in capacities: We can likewise utilize worked in capacities like int(), float() and complex() to change over into various sorts unequivocally.
a = 2
print(float(a))
b = 5.6
print(int(b))
c = '3'
print(type(int(c)))
d = '5.6'
print(type(float(c)))
e = 5
print(complex(e))
f = 6.5
print(complex(f))
Yield:
2.0
5
<class 'int'>
<class 'float'>
(5+0j)
(6.5+0j)
At the point when we convert float to int, the decimal part is shortened.
Read Full Article: Python Numbers
Comments
Post a Comment