Locked lesson.
About this lesson
Exercise files
Download this lesson’s related exercise files.
Data Type Conversion.docx59 KB Data Type Conversion - Solution.docx
59 KB
Quick reference
Data Type Conversion
It is possible to convert between different data types.
When to use
Use this anytime you need to change the type of data you're working with.
Instructions
Changing between data types with Python is pretty easy.
To determine the data type you are currently using, use the type function:
print(type(variable_name))
To convert from an int to a float:
float(variable_name)
To convert from a float to an int:
int(variable_name)
To convert from an int to a string:
str(variable_name)
To convert from a list to a tuple:
tuple(list_name)
To convert from a tuple to a list:
list(tuple_name)
Hints & tips
- int(variable_name)
- str(variable_name)
- tuple(list_name)
- list(tuple_name)
Lesson notes are only available for subscribers.