What is type conversion in Python?
Type conversion refers to the conversion of one data type into another.
int() – converts any data type into integer type
float() – converts any data type into float type
ord() – converts characters into integer
hex( ) – converts integers to hexadecimal
oct() – converts integer to octal
tuple() – This function is used to convert to a tuple.
set() – This function returns the type after converting to set.
list() – This function is used to convert any data type to a list type.
dict() – This function is used to convert a tuple of order (key,value) into a dictionary.
str() – Used to convert integer into a string.
complex(real,imag) – This functionconverts real numbers to complex(real,imag) number.00
Yeah! as @pratikkr0444 said type conversation refers to conversation of one data type in to another, below you can find the example code for the conversation
Python code to demonstrate Type conversion
using int(), float()
s = “10010”
printing string converting to int base 2
c = int(s,2)
print (“After converting to integer base 2 : “, end=””)
printing string converting to float
e = float(s)
print (“After converting to float : “, end=””)
Python defines type conversion functions to directly convert one data type to another which is useful in day to day and competitive programming. This article is aimed at providing the information about certain conversion functions.
1. int(a,base) : This function converts any data type to integer . ‘Base’ specifies the base in which string is if data type is string.
2. float() : This function is used to convert any data type to a floating point number