A Python comment begins with a hash symbol #. Everything after it on that line is ignored by Python.
# Display a friendly message
print("Welcome!")Line-by-line explanation
- The first line starts with
#, so it is a comment. Python does not display it. - The second line is code. It displays
Welcome!.
Good comments explain why something exists or clarify an unusual choice. They should not merely repeat an obvious instruction.
print("Try again in 30 seconds") # The server limits requestsLine-by-line explanation
print(...)displays the message.- The text after
#explains why the user must wait. - Python ignores the comment while running the line.