Skip to main content

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
Submitted by devanshi.srivastava on July 1, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.