Learn / Python / Variables and Types

Beginner 12 min

Variables and Types

Names, assignment, and the core built-in types: int, float, str, and bool.

What you will learn

  • Assign and reassign variables
  • Use type() to inspect values
  • Cast between types

A variable is a name bound to a value. Python figures out the type at runtime — you do not declare it.

Core types

python
age = 28
price = 19.99
name = "Amar"
active = True

print(type(age), type(price), type(name), type(active))

Type conversion

python
n = int("42")
s = str(3.14)
print(n + 1, s)

Try it yourself

Create variables for a product title, price, and in-stock flag. Print a one-line summary string.