Variables
Learn how to use Python variables as labeled storage boxes for data, and see how to name and update them.
Learning Goals
The Core Concept
Variables are just names that point to values stored in your computer's memory. Think of a variable as a labeled container or a sticky note. You write a label, assign it a value using the equals sign (=), and Python stores it. Later, you can just use that label instead of typing the value again.
Python is smart enough to figure out what kind of data you're storing. You don't need to declare if it's text or a number beforehand. You can also reassign a variable to a different value at any time.
Visual guide
Python automation process
A simple original diagram to connect the lesson idea with real project flow.
Code & Implementation
# Assigning values to variables
username = "Alex_Dev"
login_attempts = 3
is_active = True
# Printing variables
print("User name is:", username)
print("Attempts remaining:", login_attempts)
# Modifying a variable value
login_attempts = login_attempts - 1
print("Updated attempts:", login_attempts)Expected Output
User name is: Alex_Dev Attempts remaining: 3 Updated attempts: 2
A Simple Scoreboard Tracker
Hands-on practice task
The Challenge
Create a script that stores a team's name and their score. Start the score at 0, simulate scoring a goal (add 1 point), and print the updated board.
Helpful Hints
- •Set team_name = "Warriors" and score = 0.
- •Update the score with score = score + 1.
- •Print both variables together.
Quick Knowledge Check
Can I use dashes (-) in variable names?
What happens if I reference a variable before creating it?
Continue Learning
Next steps after this lesson
Create a script that stores a team's name and their score. Start the score at 0, simulate scoring a goal (add 1 point), and print the updated board.
Supercharge your career workflows!
Discover free online utilities to format data, build job applications, and automate your productivity routine with TechIdea.