Python variables are a crucial part of the language because you can use them in other expressions too:
>>> result = 15 >>> 4 * result 60 >>> result - result 0 >>>
I used the word expressions without explaining what an expression is, let’s fix that:
Anything that evaluates to a value, is a legal expression in Python. These are all valid expressions because Python can evaluate them to a value:
# Evaluates to 9: 3 * 3 # Evaluates to 19 if the variable result is 15: result + 4 # Simply evaluates to 2: 2
What you see above the expressions, are called comments. These are little notes you can leave behind for yourself or others, e.g. to explain your code and such. Anything that follows a hash symbol (the #) is seen as a comment and ignored by the Python interpreter. I’ll tell you more about comments later on, but let’s first learn more about variables, because it’s an important subject that is at the core of programming in general.
A value assigned to a variable does not have to be a number. Python has several data types besides numbers, and they can all be the result (the value) of an expression. One such data type is the string, which is the subject of the next lesson! But there are others too, like booleans, tuples, lists, and dictionaries that you’ll learn about later on in this course.