Python: Explicit Type Conversion

In Python, this method is need user involvement to convert the variable data type into certain data type in order to the operation required. This type of conversion is also called typecasting because the user casts (changes) the data type of the objects.

Mainly in type casting can be done with these data type function:

  • Int() : Int() function take float or string as an argument and return int type object.
  • float() : float() function take int or string as an argument and return float type object.
  • str() : str() function take float or int as an argument and return string type object.

Example:

a = 4
type(a)
num = float(a)

print(num)
print(type(num))

Output:

4.0
<class 'float'>
Tags