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()

# initializing string

s = β10010β

# printing string converting to int base 2

c = int(s,2)

print (βAfter converting to integer base 2 : β, end=ββ)

print Β©

# printing string converting to float

e = float(s)

print (βAfter converting to float : β, end=ββ)

Thank you,

Happy learning

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

.

Type conversion is used to convert one type of data into another.There are two types of type conversion.One is type casting(explicit conversion) and the other is type coercion(implicit conversion).

eg for type casting- a=int(b) such that b is a number in string format.

eg for type coercion- a=10.4,b=2

quotient=a/b

Here data type of b is indirectly converted from integer to float.