Python 101Free
FOUNDATIONS

Variables and Types

How Python names values and what built-in types you start with.

SECTION 01

The four core types

Most Python programs do their work with four scalar types. int for whole numbers, float for decimals, str for text, bool for true and false. There are more types underneath, but these are the ones you reach for first.

Values have a type, but variables do not. The same name can point at an integer one moment and a string the next. Python figures the type out from whatever object the name currently refers to.

This is why Python feels flexible: you do not declare types up front. The flip side is that a typo can quietly leave a name pointing at the wrong kind of thing. Reading code carefully matters more than it does in a language with type declarations.

python
x = 7          # int
y = 3.14       # float
name = "Ada"   # str
ok = True      # bool

x = "hello"    # rebinding to a different type is fine
2 more sections

Create a free account to access all sections and animations.

Create free accountAlready have an account? Sign in