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 = 10 and A = 77 are completely different variables.
name = 'Anna'
Name = 'Karen'
print(name, Name)
name = 'Anna'
name = 'Karen'
print(name, name)
The first program will print Anna Karen as the variables name and Name are different variables and they can store different information. Yet, the second program would print Karen Karen as the name variable is the same - we just re-assign the value of the name to be Karen on the second line of the program.
Challenge
Write a program that stores the value July in the variable called best_month. The program should print The best month of the year is: followed by the variable best_month.
Then assign the value March to the variable best_month and print: I changed my mind, the best month is actually: followed by the variable best_month.