#program for type conversion

rno=23
print(“int to int:”,rno," “,type(rno),” “, int(rno),” “,type(int(rno))
print(“int to float:”,rno,” “,type(rno),” “, float(rno),” “,type(float(rno))
print(“int to str:”,rno,” “,type(rno),” “, str(rno),” “,type(str(rno))
print(“int to bool:”,rno,” “,type(rno),” “, bool(rno),” “,type(bool(rno))
print(“int to complex:”,rno,” “,type(rno),” “, complex(rno),” ",type(complex(rno))
o/p:
int to int: 23 <class ‘int’> 23 <class ‘int’>
int to float: 23 <class ‘int’> 23.0 <class ‘float’>
int to str: 23 <class ‘int’> 23 <class ‘str’>
int to bool: 23 <class ‘int’> True <class ‘bool’>
int to complex: 23 <class ‘int’> (23+0j) <class ‘complex’>

salary=10.89

print(“float to int:”,salary," “,type(salary),” “,int(salary),” ",type(int(salary)))

print(“float to float:”,salary," “,type(salary),” “,float(salary),” ",type(float(salary)))

print(“float to str:”,salary," “,type(salary),” “,str(salary),” ",type(str(salary)))

print(“float to bool:”,salary," “,type(salary),” “,bool(salary),” ",type(bool(salary)))

print(“float to complex:”,salary," “,type(salary),” “,complex(salary),” “,type(complex(salary)))
float to int: 10.89 <class ‘float’> 10 <class ‘int’>
float to float: 10.89 <class ‘float’> 10.89 <class ‘float’>
float to str: 10.89 <class ‘float’> 10.89 <class ‘str’>
float to bool: 10.89 <class ‘float’> True <class ‘bool’>
float to complex: 10.89 <class ‘float’> (10.89+0j) <class ‘complex’>
Traceback (most recent call last):
File “c:\Users\santoss\OneDrive\Desktop\python_visualcode\typeconversion.py”, line 20, in
print(“str to int:”,name,” “,type(name),” “,int(name),” ",type(int(name)))
^^^^^^^^^
ValueError: invalid literal for int() with base 10: ‘Edyoda’
PS C:\Users\santoss\OneDrive\Desktop\python_visualcode> python add.py

name=“Edyoda”

print(“str to int:”,name," “,type(name),” “,int(name),” ",type(int(name)))

print(“str to float:”,name," “,type(name),” “,float(name),” ",type(float(name)))

print(“str to str:”,name," “,type(name),” “,str(name),” ",type(str(name)))

print(“str to bool:”,name," “,type(name),” “,bool(name),” ",type(bool(name)))

print(“str to complex:”,name," “,type(name),” “,complex(name),” “,type(complex(name)))
o/p
Traceback (most recent call last):
File “c:\Users\santoss\OneDrive\Desktop\python_visualcode\typeconversion.py”, line 20, in
print(“str to int:”,name,” “,type(name),” “,int(name),” ",type(int(name)))

night=True

print(“str to int:”,night," “,type(night),” “,int(night),” ",type(int(night)))

print(“str to float:”,night," “,type(night),” “,float(night),” ",type(float(night)))

print(“str to str:”,night," “,type(night),” “,str(night),” ",type(str(night)))

print(“str to bool:”,night," “,type(night),” “,bool(night),” ",type(bool(night)))

print(“str to complex:”,night," “,type(night),” “,complex(night),” ",type(complex(night)))
o/p
str to int: True <class ‘bool’> 1 <class ‘int’>
str to float: True <class ‘bool’> 1.0 <class ‘float’>
str to str: True <class ‘bool’> True <class ‘str’>
str to bool: True <class ‘bool’> True <class ‘bool’>
str to complex: True <class ‘bool’> (1+0j) <class ‘complex’>