Why are there two kinds of comments?


#1

Question

An earlier exercise showed comments using the # symbol, so why do we need another type of comment?

Answer

They both come in handy in different ways!

Single-line comments are great when you need to:

  1. Write a comment on the same line (inline), perhaps to explain a variable or value

  2. Comment out a single line of code so that it doesn’t run

Multi-line comments are useful when you need to:

  1. Comment out large blocks of code

  2. Write documentation for a program or function

Ultimately the style and choice is up to you, but if you’re interested in going down the style guide rabbit hole, here’s a link to Python’s PEP 8 style guide!


FAQ: Learn Python - Python Syntax - Multi-line Strings