Python Variables
The last page left a name that holds a value. guest = "lida" stores the text lida under the name guest. The = here stores. It does not ask whether two sides match. print(guest) writes the stored text. The output is lida. The word guest is not in the output.
guest = "lida"
print(guest)
Quotes around the name print the word
print(guest) uses the name, so you see lida. print("guest") is text, so you see the word guest. The quotes decide. A name has no quotes around it. Text does.
guest = "lida"
print(guest)
print("guest")
The output is two lines. First lida. Then guest. The first print uses the stored text. The second print shows the characters inside the quotes. Same spelling, two different jobs.
No quotes on the right looks up a name
guest = lida, with no quotes, does not store the text lida. Python looks for a name called lida. Nothing stored that name, so the program stops. The quotes are what make lida text.
A later line replaces the stored text
Write guest = "tea" after guest = "lida" and the name guest now holds tea. lida is no longer stored under that name. print(guest) shows tea.
guest = "lida"
guest = "tea"
print(guest)
A second name does not erase the first
drink = "tea" creates another name. guest still holds lida. print(guest) then print(drink) writes lida, then tea. Two names, two stored texts.
guest and Guest are different names
The stored name is guest, all lowercase. print(Guest) looks for a different name. That name was never stored, so the program stops. Match the spelling you stored.
Left for the next page
This page does not read a line you type, does not do arithmetic, and does not start a note with #. The next page is a line you type, which the program reads. The name still holds whatever was stored.
Check yourself
- guest = "lida" then print(guest) writes lida.
- print("guest") writes the word guest.
- guest = lida with no quotes stops, because lida is not a stored name.
- A second guest = "tea" replaces lida.
- drink = "tea" does not change what guest holds.
Misses
- Expecting the word guest from print(guest)
- Expecting lida from print("guest")
- Dropping the quotes in guest = lida and hoping the text is stored
- Thinking the first guest = "lida" survives a later guest = "tea"
- Writing print(Guest) after storing guest
Keep
- guest = "lida" stores text under a name. print(guest) shows lida.
- print("guest") shows the word guest. Quotes make text. A bare name uses what was stored.
- guest = lida with no quotes looks up a name and stops when that name was not stored.
- A later guest = "tea" replaces the stored text. print(guest) then shows tea.
- The next page reads a line you type.
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top