Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
The print function
Variables
8. Creating variables
Math in Python
The input function
Summary

Instruction

Good! Let's move on to variables. Variables in programming languages are named places in computer memory where we can store data and retrieve it later. They are a bit like cells in Excel.

In Python, you provide your own names for variables, but they must start with either a letter or an underscore (_). In other words, a variable cannot start with punctuation or digits.

current_age = 25

This line of code:

  • Creates a new variable named current_age.
  • Assigns the value of 25 to current_age.

The equals sign (=) means 'assign the value of' in Python. Next, you can use print() to show the value of current_age:

print(current_age)

In Python variable names are case sensitive. This means that current_age and CURRENT_AGE are two different variables! Remember that each command in Python should start from a new line.

Exercise

Create a variable named temperature, assign a value of 15 to it, and print the variable value.

Stuck? Here's a hint!

You will need two lines of code. First, create the variable and assign the value. Second, print the result.