In the last 2 tutorials, you learnt about Python Basics: Numbers, Expressions, Strings, and Functions. In this tutorial, you'll learn about Python variables. Let's get started!
Variables
An important concept in programming is variables. Variables are used to store values.
A good analogy for the variable is a box. You can imagine the name of the variable as the label on the box, and the value of the variable as what's stored inside it.
Let's create a new variable called name, and then print its value.
type=codeblock|id=py3_variable|autocreate=python3name = "Commonlounge"print(name)
Output:
Commonlounge
The above is equivalent to saying: Store the value "Commonlounge" in variable name.
As you may have noticed, we did print(name) instead of print("name"). The first one (without the quotes) says, print the value of the variable name. The second one (with the quotes) says, print the string "name".
Yippee! Your first variable! :)