Python Revision Variables
Setting a variable is easy in Python. Whenever any word or number follows a = symbol, it is
regarded by Python as a variable.
For example, to set a variable called bandName to The Beatles we would do this:
bandName = “The Beatles”
Now we can concatenate the variable with strings. bandName = “The Beatles”
print(“The most successful band ever were “+ bandName)
Try these out on python and see if you can correct the errors:
1
bandName = "The beatles"
print(bandName " had 27 number 1 singles")
Correct code:
2
bandName = "The beatles"
print(“bandName”, are the most successful band ever with 15 number 1 albums)
Correct code:
We can change variables by reassigning the variable as something else. for example:
batman = “Adam West”
batman = “Michael Keaton”
batman = “George Clooney”
batman = “Christian Bale”
Every time the variable batman is reassigned as something else it forgets the old name.
There is no way to bring that back unless it is reassigned as a previous value.
Python Revision Variables
Use the Python interpreter to :
1. Assign Christian Bale as the variable for batman.
2. Print the variable for batman
3. Assign Ben Affleck
4. Print the variable for batman
Your code: