■ Python Type Casting Cheat Sheet
Type Casting (or Type Conversion) means converting one data type into another. Python supports
several built-in functions for this.
Function Description Example
int(x) Converts x to an integer int("5") → 5
float(x) Converts x to a float float("3.14") → 3.14
str(x) Converts x to a string str(10) → "10"
bool(x) Converts x to a boolean bool(0) → False
list(x) Converts x to a list list("abc") → ['a', 'b', 'c']
tuple(x) Converts x to a tuple tuple([1, 2]) → (1, 2)
set(x) Converts x to a set set([1, 2, 2]) → {1, 2}
Notes: Strings that look like numbers (e.g. "10") can be cast to int or float. Empty values like "", [], 0
become False when cast to bool. Casting can fail if the format is invalid: e.g. int("hello") causes an
error.