Variables can have different names. We can have a variable
year = 2022, a variable
month = 'July', a variable called
game = 'Red Dead Redemption 2', etc.
Yet, there are limitations to naming the variables. It’s important to note that variables can only contain letters, numbers, and the
_symbol. On top of that, variables cannot start with a number.
num1 = 512 # OK! This is a valid expression num_2 = 1024 # OK! This is a valid expression 3_num = 256 # NOT OK! Variables cannot start with a number some_long_variable_name = 10 # OK! longVariableName = 'hello' # Still OK, but it's preferable to use _ to separate words in the name of a variable
Variables are case-sensitive, meaning that
a = 10and
A = 77are completely different variables.
name = 'Anna' Name = 'Karen' print(name, Name)
name = 'Anna' name = 'Karen' print(name, name)
The first program will print
Anna Karenas the variables
Nameare different variables and they can store different information. Yet, the second program would print
Karen Karenas the
namevariable is the same - we just re-assign the value of the name to be
Karenon the second line of the program.
Write a program that stores the value
Julyin the variable called
best_month. The program should print
The best month of the year is:followed by the variable
Then assign the value
Marchto the variable
I changed my mind, the best month is actually:followed by the variable