Python Variables — A Clear Beginner's Guide
Learn Python variables in 5 minutes. Naming rules, dynamic typing, arithmetic, and the single biggest beginner mistake — with a runnable code editor.
Runs in your browser via Pyodide — no signup, no install. Want auto-graded full exercises + videos? See the 7-Day Python Sprint.
A variable in Python is just a name pointing at a value. Unlike Java or C, you don't declare a type — you just write name = value and Python figures out the type from whatever you assigned.
name = "Alice"
age = 30
pi = 3.14159
is_active = True
Python is dynamically typed: the same variable can hold a number on one line and a string on the next. The type belongs to the *value*, not the name.
Naming rules
Variable names must start with a letter or underscore, can contain letters, digits, and underscores, and are case-sensitive. price and Price are two different variables.
The Python community uses snake_case — words joined with underscores, all lowercase: customer_name, total_revenue, is_logged_in. Stick with this; reviewers will trust your code more.
Arithmetic operators
| Operator | Meaning | Example |
|---|---|---|
+ - * / | Standard arithmetic | 10 / 3 → 3.333... |
// | Integer (floor) division | 10 // 3 → 3 |
% | Modulo (remainder) | 10 % 3 → 1 |
** | Exponent | 2 ** 10 → 1024 |
Two surprises worth knowing: / *always* returns a float, even when the result is whole. And ** — not ^ — is exponent. ^ in Python is bitwise XOR, which is rarely what you want.
Comparison and logic
Comparison operators return a boolean (True or False):
10 == 10 # True — note: two equals
10 != 5 # True
0 < x < 100 # chained comparison, valid in Python
Logical operators use English words, not symbols:
age >= 18 and country == "IN"
not is_admin
x == 0 or y == 0
The single biggest beginner mistake
Using = when you mean ==. The first is assignment (set a variable). The second is comparison (returns True or False). Python won't let you accidentally assign inside an if, which is a small mercy.
Where this fits in the 7-Day Python Sprint
Variables are covered on Day 1, alongside data types, lists, tuples, sets, and dictionaries. By the end of Day 1 you're writing real Python code with all five collection types.
Practice
Auto-graded — run in your browser, no signup.
Exercise 1: Define `price = 200` and `discount_pct = 25`, then compute `final` as the discounted price (rounded to 2 decimals).
Runs in your browser via Pyodide — no signup, no install. Want auto-graded full exercises + videos? See the 7-Day Python Sprint.
Like this tutorial? Get the full Python Sprint.
7 days, daily videos, auto-graded labs, AI tutor, mini-project. 1-year content access.
See the Python Sprint