Skip to content

Python Programming · Week 2

Variables

Step 1 of 6

Understanding Variables

Variables are fundamental building blocks in programming. They act as containers that store information in a computer's memory, allowing us to work with data throughout our program.

To create a variable in Python, we use the assignment operator (=). Here's an example:

x = 100

In this example, we've created a variable named 'x' and assigned it the value 100. We can now use 'x' throughout our program to refer to this value.

Variables can store different types of data, such as numbers, text, or more complex structures. The type of data a variable holds can change during the execution of a program, which is why Python is called a dynamically-typed language.

Now, let's try creating a variable named my_variable with a value of 50.

Write your code in the editor below and click "Run" to see the result. Remember to use the print() function to display the value of your variable.

Starter code
# Create a variable named my_variable with a value of 50
# Then print the variable

Write your code here

Make it print 50

Did it work?

Your program should print this:

50