Python Comments
The last page promised a note that Python does not run. The mark is #. From that mark to the end of the same line, Python skips. The note is for you. It is not printed, and it is not a statement.
A note on its own line, or after the code
A whole line can be a note. Or the note can start after a statement, on that same line. Either way the skip stops at the end of the line. The next line is ordinary Python again.
# guest
print("lida")
print("tea") # drink
The output is still two lines. First lida. Then tea. The words guest and drink never appear. The quotes around lida and tea are text that print shows. The # notes are not.
The note does not reach upward
A # on one line does not silence the line above it. print("lida") runs. Only the rest of the line that contains # is skipped.
Turning a line off
Put # at the start of a line and the whole line becomes a note. print("lida") with a # in front does not run. The line under it is still a real statement.
# print("lida")
print("tea")
The output is one line: tea. lida is still written in the file, but it sits inside the note, so Python never runs that print.
# is not a quote
"tea" is text that print shows. # tea is a note that vanishes. Mixing them up is how a line you meant to run disappears, or a note you meant to hide shows up as text.
Left for the next page
This page does not create a name, does not move a line inward, and does not install Python. The next page is a name that holds a value. The note stays a note.
Check yourself
-
guest is not printed.
- print("lida") and then print("tea") # drink still prints lida, then tea.
-
print("lida") does not print lida.
- The skip stops at the end of the line. It does not climb to the line above.
Misses
- Expecting guest or drink in the output
- Treating # like quotes
- Putting # in front of print("lida") and still waiting for lida
- Thinking a note on the next line turns off the line above
- Indenting the note and calling that a new rule; the block rule did not change
Keep
-
starts a note. Python skips to the end of that line.
- The two prints still write lida, then tea. The notes are not shown.
-
print("lida") is only a note. print("tea") under it still runs.
- A note does not reach the previous line.
- The next page holds a value under a name.
🧠 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