Use # for each line, or use triple quotes for a block of text. Python does not have a special multiline comment syntax, so the common practice is to stack single-line comments with # or use a triple-quoted string when you want to temporarily disable a block of code.

Two common ways

  1. # on every line:
python

# This is a comment
# that spans multiple lines
# in Python
print("Hello")
  1. Triple quotes:
python

"""
This looks like a multiline comment,
but it's really a string literal.
"""
print("Hello")

Important note

Triple quotes are often used as docstrings or as a convenient way to block out code, but they are not true comments in the language syntax. For normal commenting, # is the safest and clearest choice.

Best practice

  • Use # for real comments and explanations.
  • Use triple quotes mainly for docstrings.
  • In editors, you can often select multiple lines and toggle comments with a shortcut.

Would you like a quick example of how to comment out a whole block of code in VS Code or Jupyter?