Download our e-book of Introduction To Python
Balasaheb Garule
3 years ago
n = 10000000000000000001
print(type(n))
<class 'int'>
fp = 3.14
print(type(fp))
<class 'float'>
c = 3+4j
print(type(c))
print(c.real)
print(c.imag)
<class 'complex'>
3.0
4.0
p = 10 # int
q = 3.14 # float
r = 2+4j # complex
print(“convert from python int to float”)
x = float(p)
print(type(x))
print(x)
print(“convert from python float to int”)
y = int(q)
print(type(y))
print(y)
print(“convert from python int to complex”)
z = complex(p)
print(type(z))
print(z)
print(“convert from python int to string”)
s = str(p)
print(type(s))
print(s)
convert from python int to float
<class 'float'>
10.0
convert from python float to int
<class 'int'>
3
convert from python int to complex
<class 'complex'>
(10+0j)
convert from python int to string
<class 'str'>
10
#python program to add two numbers
# integer number addition
num1 = 10
num2 = 20
add = num1+ num2
print(“Integer Addition : ”,add)
# float number addition
num1 = 10
num2 = 2.5
add = num1 + num2
print(“Float Addition : ”,add)
#Complex number addition
num1 = 5+3j
num2 = 2
add = num1 + num2
print(“Complex Addition : ”,add)
# Real and imaginary parts are added to get the result.
Integer Addition : 30
Float Addition : 12.5
Complex Addition : (7+3j)
#python program to subtract two numbers
# integer number Subtraction
num1 = 10
num2 = 20
sub = num1- num2
print(“Integer Subtraction: ”,sub)
# float number Subtraction
num1 = 10
num2 = 2.5
sub = num1 - num2
print(“Float Subtraction: ”,add)
#Complex number Subtraction
num1 = 5+3j
num2 = 2
sub = num1 - num2
print(“Complex Subtraction: ”,sub)
# Real and imaginary parts are Subtract to get the result.
Integer Subtraction : -10
Float Subtraction : 7.5
Complex Subtraction : (3+3j)
#python program to Multiplication two numbers
# integer number Multiplication
num1 = 10
num2 = 20
mul = num1- num2
print(“Integer Multiplication: ”,mul)
# float number Multiplication
num1 = 10
num2 = 2.5
mul = num1 - num2
print(“Float Multiplication: ”, mul)
#Complex number Multiplication
num1 = 5+3j
num2 = 2
mul = num1 - num2
print(“Complex Multiplication: ”, mul)
# Real and imaginary parts are multiply by num2 value to get the result.
Integer Multiplication : 200
Float Multiplication : 25.0
Complex Multiplication : (10+6j)
#python program to Division two numbers
# integer number Division
num1 = 10
num2 = 20
div = num1/ num2
print(“Integer Division: ”,div)
# float number Division
num1 = 10
num2 = 2.5
div = num1 / num2
print(“Float Division: ”, div)
#Complex number Division
num1 = 5+3j
num2 = 2
div = num1 / num2
print(“Complex Division: ”, div)
# Real and imaginary parts are divide by num2 value to get the result.
Integer Division : 0.5
Float Division : 4.0
Complex Division : (2.5+1.5j)
n = int(5.0/2)
print(n)
2
n = 5 // 2
print(n)
2
n = 3**2
print(n)
9
m = 3 ** -1
print(m)
0.3333333333333333
r = 5 % 2
print(r)
1