Learning outcomes
By the end of this chapter, you should be able to:- define a variable in simple terms
- write valid variable names
- assign and reassign values
- explain dynamic typing in Python
30-minute recording plan
0-6 min: what variables are and why needed6-12 min: assignment statement and reassignment12-18 min: variable naming rules and style18-24 min: dynamic typing basics24-30 min: exam-focused recap and practice
Chapter snapshot
- Think of a variable as a label attached to a value.
- Labels make code readable:
total_marksis clearer than raw numbers repeated everywhere. - In Python, a variable can point to different value types over time.
What is a variable?
A variable is a name that refers to a value stored in memory. You can read it as: “store this value in this name.”age and name are variable names.
Why do we need variables?
- avoid repeating fixed values
- update a value once and reuse it everywhere
- improve readability and debugging
- make formulas and logic easier to understand
Assignment statement
Python uses= for assignment.
= means “store value in variable”. It does not mean “equals” in mathematics.
Variable naming rules
- use letters, digits, and
_ - must not start with a digit
- no spaces in names
- names are case-sensitive (
marksandMarksare different) - do not use keywords (
if,for,class, …)
total_marks, student_name, is_passed
Naming style (best practice)
- use
snake_casein Python:final_score,unit_price - avoid one-letter names except short math loops (
i,j) - choose names that show meaning, not just type
Dynamic typing in Python
In Python, variable type is determined at runtime.Mini showcase: monthly expense update
Spent: 2700Left: 2300
Exam-focused points
- variable: named memory location/reference
- assignment operator is
= - equality comparison uses
== - Python is dynamically typed
Practice questions
- Write 5 valid and 5 invalid variable names.
- Predict output:
- Correct the errors:
