Ch 3 · Variables — Your Data Containers · Python
Topic 3 of 13 in Python — Complete Tutorial (Beginner) — 4 lessons.
What is a Variable?
Imagine you are playing a video game and your character earns points. The game needs to remember your score at all times — it needs somewhere to store that number. In programming, we use a variable for exactly this. A variable is a named storage location in the computer's memory that holds a piece of data. You give it a name, you put a value inside it, and you can read or change that value any time your program needs to.
Assigning and Updating Variables
In Python, you create a variable the very first time you assign a value to it, and you can change that value as many times as you like simply by assigning again. Each new assignment replaces whatever was in the box before. This is perfect for values that change as your program runs — a score that goes up, a countdown that goes down, a name that gets corrected.
Naming Conventions
Choosing good names for your variables is one of the most important skills in programming. The name should immediately tell anyone reading your code what the variable contains — without them needing to look at the value. A name like x or n tells you nothing. A name like number_of_students or is_raining tells you exactly what is stored there.
Variables in Action: A Full Example
Let us bring everything together in a real mini-program that uses multiple variables the way you would in an actual project. Notice how the variable names make the code read almost like plain English — that is the goal of good Python.
All topics in Python Beginner
- Introduction to Programming & Python
- Your First Python Program
- Variables — Your Data Containers
- Data Types — Kinds of Values
- Operators & Expressions
- Conditional Statements
- Loops & Iterations
- Functions
- Lists — Collections of Data
- Dictionaries & Classes
- Strings — Working with Text
- Error Handling
- Mini-Projects & Practice