Lesson 02

What's a variable?

What is a Variable?

A variable is a way to store information in a program.

You can think of a variable as a label attached to a value.

Real-world example:

If you write your name on a sticky note and put it on a box, the name is the variable and what’s inside the box is the value.

Creating a Variable in Python

In Python, you create a variable by using the equals sign =.

name = "Cienna"

This tells Python:

  • Create a variable called name
  • Store the text "Cienna" inside it

Using Variables with print()

You can use print() to display what is stored inside a variable.

name = "Cienna"
print(name)

Python will display:

Cienna

Important Rules

  • Variable names cannot have spaces
  • They should start with a letter
  • Python is case-sensitive (Namename)

Variables Challenge

Your task is to:
  • Create a variable called name
  • Store your name as text
  • Print the variable
Student Name:
Output:
Loading Python…