Variables
Inside print(), a variable name without quotation marks makes Python find the value stored in that variable and display it. Text wrapped in quotation marks is a string literal: Python displays exactly those characters and does not look for a variable with that name.
playlistName = 'Revision Mix'
print(playlistName)
print('playlistName')
print('72 minutes long')Output:
Revision Mix
playlistName
72 minutes long
The first two print lines use the same word, playlistName, but only the first has no quotation marks. The first print() displays the value stored in the variable. The second displays the characters playlistName, because the quotation marks turn it into text. The variable still holds its value afterwards; printing does not change it.
To work out what a line prints, check what sits inside the brackets. If it is a variable name, find its current value first, then print that value. If it is inside quotation marks, copy the characters between the marks exactly, including capital letters and spaces.
| Inside print() | What is displayed |
|---|---|
playlistName (a variable) | The value the variable currently holds |
'playlistName' (text in quotation marks) | The characters playlistName |