What is type conversion in Python?

Python provides you with a much-needed functionality of converting one form of data type into the needed one and this is known as type conversion.

Type Conversion is classified into types:

  1. Implicit Type Conversion: In this form of type conversion python interpreter helps in automatically converting the data type into another data type without any User involvement.

  2. Explicit Type Conversion: In this form of Type conversion the data type inn changed into a required type by the user.

Various Functions of explicit conversion are shown below:

int() –  function converts any data type into integer.

float() –   function converts any data type into float.

ord() – function returns an integer representing the Unicode character

hex() –  function converts integers to hexadecimal strings.

oct() –   function converts integer to octal strings.

tuple() – function convert to a tuple.

set() – function returns the type after converting to set.

list() – function converts any data type to a list type.

dict() – function is used to convert a tuple of order (key,value) into a dictionary.

str() –  function used to convert integer into a string.

complex(real,imag) – function used to convert real numbers to complex(real,imag) numbers.