← Python from Scratch Lesson 3 of 78 · 10 XP

Comments

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

A comment is text for humans that Python skips entirely. It starts with # and runs to the end of the line:

# This program says hello
print("Hello")   # a comment can also come after code

What they're for:

  • to explain why the code is written this way (what it does is usually obvious anyway);
  • to temporarily "switch off" a line without deleting it — this is called commenting it out.
print("This line will run")
# print("And this one won't")

For long explanations people sometimes use a string in triple quotes. If it isn't assigned to anything, it has no effect:

'''
Program: calculator
Author: me
'''

Task. The starter code has three print lines. Comment out the second one so the program prints only One and Three. You may not delete the line — only comment it out.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.