Search⌘ K
AI Features

Type Conversions

Learn how to convert data types in Python using functions like int, float, bool, and str, along with collections conversions. Understand key concepts in type checking by contrasting the use of type and isinstance functions to write more reliable Python code.

Data type conversion functions

To convert a value from one data type to another, it is often possible to use the name of the desired data type as if it were a function. For example:

Conversion Result
int(5.7) 5
int("5") 5
float(5) 5.0
float("5.7")
...