Variables & Types

Python is dynamically typed but the types still matter. Learn what a variable really is, the core built-in types, and how to inspect them.

⏱ 7 min read Beginner Python Updated May 2026

What you'll learn

  • The difference between a variable and the value it points to
  • The 6 built-in types you'll use 95% of the time
  • How to inspect a value's type with type() and isinstance()
Prerequisites: python/getting-started

A variable in Python isn’t really a “box” that holds a value — it’s a name that points to an object somewhere in memory. This is more than a trivia; it explains some Python behaviors that surprise people coming from other languages.

A name → an object

Python
Ready
Output
(click Run)

x is y is True because both names point to the same object. The = did not copy the list; it just bound another name to it. To get an independent copy, you’d write y = x.copy() or y = list(x).

The core built-in types

These six show up everywhere:

TypeExampleMutable?
int42, -1000
float3.14, 1e-9
str"hello"no
boolTrue, False
list[1, 2, 3]yes
dict{"a": 1}yes

You’ll also meet tuple ((1, 2), immutable list), set ({1, 2}, unordered, unique elements), and None (the absence-of-value singleton).

Python
Ready
Output
(click Run)

type(x).__name__ gives the type name as a string. !r in the f-string calls repr(), which gives an unambiguous representation — useful when inspecting values.

Dynamic typing, but typed values

Python doesn’t require you to declare types — a variable can point at any type at any time. But every value has a type, and operations only work on compatible types.

Python
Ready
Output
(click Run)

In production code you’ll add type hints to make the intent explicit and let mypy or pyright catch type errors before runtime. We cover that in a later lesson.

Casting between types

Python
Ready
Output
(click Run)

isinstance vs type ==

Prefer isinstance(x, T) over type(x) == T — it respects inheritance, which matters once you start using classes.

isinstance(True, int)   # True — bool is a subclass of int
type(True) == int       # False

Quick check

Quick check

0/3 answered
Q1.After `x = [1, 2]; y = x; y.append(3)`, what is `x`?
Q2.Which expression is the idiomatic 'is this empty string or None?' check?
Q3.What does `bool('False')` return?

Finished the lesson?

Mark it complete to track your progress and keep your streak alive. +20 XP

Skip to content