runtime
03 / 250
lesson 03 Python Setup & First Programs · beginner

Comments

Notes for people that Python ignores, and a quick way to switch a line off while you test.

You'll be able to
  • Write a comment Python ignores
  • Explain a line with a short comment
  • Comment out a line instead of deleting it
The idea

A # starts a comment: Python ignores it and everything after it on that line. Comments are for people reading the code, including you next week.

Run each example to see what it prints. Running examples doesn't count toward progress.

example-1.py · Notes in a program
# Receipt for order O108752
print("Subtotal: 54.87")
print("Shipping: 0")  # free from $50
# print("DEBUG: promo WELCOME10 applied")
print("Total: 58.71")

Inside quotes, # is just a character, not a comment.

example-2.py · # in text
print("Order #1 is ready")  # this part is a comment
Review
  • # starts a comment; Python ignores the rest of the line.
  • Inside quotes, # is just text.
  • Comment a line out to switch it off without losing it.
Practise this

Loading your progress…

To master this lesson, solve both challenges without hints or the answer, and pass the concept check.

Comments — Python Setup & First Programs · Runtime