Lesson: Variables in Python ( by python assistant prompt AI )

 

Lesson: Variables in Python

[introduction]

Hello! Today we’re going to learn one of the most important fundamentals in Python: variables. By the end of this lesson, you will understand what they are, why we use them, and how to create them confidently.


[concept_explanation]

A variable is simply a name that you assign to a value in Python.
Think of it as a container that stores information you want to use later.

Python automatically understands the type of value you store—there’s no need to declare types manually (unlike some other programming languages). This makes Python very beginner-friendly.

Key points about variables:

  • A variable is created when you assign a value to a name.

  • Variables can store numbers, text, lists, and much more.

  • You can change the value inside a variable at any time.

  • Python uses the latest stable version syntax for assignments.


[python_examples]

# Creating variables age = 18 name = "Sarah" height = 1.72 # Updating a variable age = 19 # Using variables print(name, "is", age, "years old.")

[analogy]

Imagine you have a set of labeled jars.
Each jar has a label (the variable name) and something inside (the value).
If you put something new inside the jar, the label stays the same—you’ve just replaced the contents.
This is exactly how variables work.


[practice_task]

Create three variables:

  1. One to store your name

  2. One to store your age

  3. One to store your favorite number

Then print them out in a sentence.


[quiz]

  1. What is a variable in Python?

  2. True or False: You must declare a variable’s type before using it in Python.

  3. Which of these is a valid variable name?

    • 2name

    • my_name

    • my-name


[common_mistakes]

  • Starting a variable name with a number (not allowed).

  • Using spaces in variable names (use underscores instead).

  • Forgetting quotes when assigning text values.

  • Using hyphens (-) in variable names (Python treats it as subtraction).


[extra_notes]

Variable names should be descriptive. For example:

  • total_price is better than tp.
    Python also follows PEP8 naming conventions, which recommend using lowercase letters with underscores.

Comments

Popular posts from this blog

Ecommerce website

Yes, Python is an object-oriented programming (OOP) language, but it is also a multi-paradigm language

Your task is to find the missing number.