▶ Try Python

Python Data Types

Python automatically figures out the type of every value — here's what's available.

The built-in types

TypeExampleWhat it stores
int42Whole numbers
float3.14Decimal numbers
str"hello"Text
boolTrueTrue or False
list[1, 2, 3]Ordered, mutable collection
tuple(1, 2, 3)Ordered, immutable collection
dict{"a": 1}Key-value pairs
set{1, 2, 3}Unique values, unordered
NoneTypeNoneAbsence of value

Checking types

Python
type(42) # <class 'int'> type(3.14) # <class 'float'> type("hello") # <class 'str'> type(True) # <class 'bool'> type([1, 2]) # <class 'list'> type(None) # <class 'NoneType'> # isinstance() — safer than type() for checks isinstance(42, int) # True isinstance(True, int) # True! bool is a subclass of int

Type conversion (casting)

Python
int("42") # 42 — str to int float("3.14") # 3.14 — str to float str(42) # "42" — int to str bool(0) # False bool("") # False — empty string is falsy bool("hello") # True — non-empty string is truthy list((1,2,3)) # [1,2,3] — tuple to list

Mutable vs immutable

Immutable (can't change in place)
int, float, str, bool, tuple, frozenset
Mutable (can change in place)
list, dict, set
Falsy values in Python The following all evaluate to False in a boolean context: 0, 0.0, "", [], (), {{}}, set(), None. Everything else is truthy.