PDF download Download Article

Quickly turn multiple lines into comments in Python

PDF download Download Article

Trying to comment out a block of code in Python? There are multiple easy methods to do so! You can use the hash character # or turn the lines into a string. The keyboard shortcut for turning lines into code varies depending on the text editor you’re using. This wikiHow shows you how to comment out multiple lines in Python.

Things You Should Know

  • Place a # and a space before each line of code.
  • Alternatively, place """ before and after the block of code.
  • To use a keyboard shortcut, select the block of code, then press the key combination.
Section 2 of 3:

Using a Multiple-Line String

PDF download Download Article
  1. before and after the lines. This turns the lines into a multiple-line string called a docstring. When a string isn’t assigned to a variable, Python will skip it when running the code. [2]
    • You can also use three single-quotes instead ( ''' ).
    • Docstrings are typically used for programming documentation and code summaries. Python’s style guide recommends using the hash character ( # ) for multi-line block comments. [3]
    • If you’re just getting started with Python, check out how to turn integers into strings .
    EXPERT TIP

    Kevin Burnett

    Software Developer
    Kevin Burnett is a Software Developer with over 20 years of professional experience. He spent the majority of his career at Rosetta Stone, a language-learning software company. He has experience with both front and back-end development and works primarily in Ruby, Python, and JavaScript.
    Kevin Burnett
    Software Developer

    Python commenting scales strategies. For commenting Python, use # symbols and triple quotes. # contains small chunks well, while """ """ wraps multiline snippets cleanly. The former scales better as comments lengthen, improving readability.

Expert Q&A

Ask a Question
      Advertisement

      Video

      Tips

      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Thanks for submitting a tip for review!
      Advertisement

      Expert Interview

      Thanks for reading our article! If you’d like to learn more about computer programming, check out our in-depth interview with Kevin Burnett .

      About This Article

      Thanks to all authors for creating a page that has been read 60,316 times.

      Is this article up to date?

      Advertisement