Curriculum / Python / Lesson 02

Variables in Python

Python variables don't need a declared type — you simply assign a value, and Python figures out the type automatically.

2 of 11
beginner 📖 4 min read 🎯 1 question

Variables

Python variables don't need a declared type — you simply assign a value, and Python figures out the type automatically. A variable can even be reassigned to a value of a different type later, since Python is dynamically typed.

💡 Key insight Even though you don't declare types, every value in Python still has a specific type underneath — check it anytime with type().

Syntax

syntax
variableName = value

Example

type() reveals the underlying type Python inferred for a value.

py
age = 20
price = 49.99
name = "CodeyHub"

print(name, age, price)
print(type(age))
outputCodeyHub 20 49.99 <class 'int'>

Try it yourself

Copy this example into the Python compiler and run it — try changing a value and see what happens.

Quick Quiz

1. What happens if you reassign a Python variable that held an int to a string value?

Back to curriculum