Skip to content
techsnow

Python Basics

Type Conversion

int("42")       # 42
float("3.5")    # 3.5
str(99)         # "99"
int(7.9)        # 7  (cuts off the decimal)
bool(0)         # False
bool("hi")      # True
list("abc")     # ['a', 'b', 'c']

Falsy values

These count as False in an if: False, 0, 0.0, "", [], {}, (), set() and None. Everything else is truthy.