T

TechIdea

Ecosystem

Pythonbeginner8 min read

Variables

Learn how to use Python variables as labeled storage boxes for data, and see how to name and update them.

Learning Goals

1
Understand what variables are and how they store data in memory.
2
Define variables with descriptive names following PEP 8 rules.
3
Reassign variable values and trace changes during execution.
4
Avoid common variable naming errors and reserved keywords.

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

python
# 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

Required for Mastery

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?
No, dashes are interpreted as subtraction operators. Always use underscores (_) for multi-word variables (e.g., total_price).
What happens if I reference a variable before creating it?
Python will raise a NameError, informing you that the name is not defined.

Continue Learning

Next steps after this lesson

Practice task

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.

Ready to take action?

Supercharge your career workflows!

Discover free online utilities to format data, build job applications, and automate your productivity routine with TechIdea.

Growth Newsletter

Get practical AI tools, SEO tips, and growth guides weekly.

Join creators, students, and businesses scaling with TechIdea.