Loading...

Python Naming

You have four tickets, and you need a name for that number so you can use it again. The name on this page is ticket_count. The first line stores 4 under that name: ticket_count = 4. The second line asks for the name back: print(ticket_count). print looks up ticket_count and writes the number stored there.

name the four tickets

python
ticket_count = 4
print(ticket_count)

The screen shows 4. That 4 is a whole number, with no decimal point. The program finishes, and None is not written. The lookup is exact. Ticket_count is not the name you stored. print(Ticket_count) is not in this program. Add that line and it stops as NameError, because nothing was stored under Ticket_count.

store a second name on purpose

python
ticket_count = 4
Ticket_count = 9
print(ticket_count)
print(Ticket_count)

The second program is a separate try. It stores 4 under ticket_count, then stores 9 under Ticket_count. The screen shows 4, then 9, because those are two names. Both numbers are whole numbers, with no decimal point. The second program does not change the first. Run the first program again and the screen is still 4. A name has to be one word you can write again later. ticket count = 4 is not in this program. The space breaks the name, the line stops as SyntaxError, and no number is stored. A name also cannot start with a digit. 4tickets = 4 is not here. That line stops as SyntaxError, and None is not written. The word class already belongs to the language, so class = 4 is not a name you can choose. That line stops as SyntaxError too.

You can now give a number a name and ask for that same spelling later. A different capital letter is a different name. The next page is the summary and the next step.

Ask for the same spelling you stored

ticket_count holds 4. Ticket_count holds 9. A space, or a digit at the start, stops the line before a number is stored. The next page is the summary and the next step.

🧠 Test Your Knowledge

Ready to Start

Test Your Knowledge

Challenge yourself with this interactive quiz and see how well you understand the topic

❓
4
Questions
🎯
70%
To Pass
♾️
∞
Time
🔄
∞
Attempts

📝 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