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

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.[5] When a string isn’t assigned to a variable, Python will skip it when running the code.[6] [7]
    • 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.[8]
    • If you’re just getting started with Python, check out how to turn integers into strings.
    EXPERT TIP
    Kevin Burnett

    Kevin Burnett

    Software Developer
    Kevin Burnett is a Software Developer with over 20 years of professional experience. He works for SpiffWorkflow, a Python Process Automation tool for organizations. Prior to SpiffWorkflow, 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 Python, Ruby, and JavaScript. He attended the first RailsConf and the most recent PyCon US. He received an MBA and a BA in Computer Science and Spanish from Eastern Mennonite University.
    Kevin Burnett
    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.

Section 3 of 3:

Keyboard Shortcuts

PDF download Download Article

Community Q&A

Search
Add New Question
  • Question
    How to apply # on all lines of code?
    Bhoimus
    Bhoimus
    Top Answerer
    First, select the entirety of the code using Ctrl+A. Then, use the keyboard shortcut for commenting code set for your IDE. Default key combinations for popular IDEs are given in the last step above.
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement

Video

Tips

Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
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.

References

  1. Kevin Burnett. Software Developer. Expert Interview
  2. Kevin Burnett. Software Developer. Expert Interview
  3. Kevin Burnett. Software Developer. Expert Interview
  4. https://peps.python.org/pep-0008/
  5. https://www.geeksforgeeks.org/python-multi-line-statements/
  6. Kevin Burnett. Software Developer. Expert Interview
  7. https://docs.python.org/release/3.11.1/tutorial/introduction.html
  8. https://peps.python.org/pep-0257/
  9. https://code.visualstudio.com/docs/editor/codebasics

About This Article

Kevin Burnett
Co-authored by:
Software Developer
This article was co-authored by Kevin Burnett and by wikiHow staff writer, Kyle Smith. Kevin Burnett is a Software Developer with over 20 years of professional experience. He works for SpiffWorkflow, a Python Process Automation tool for organizations. Prior to SpiffWorkflow, 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 Python, Ruby, and JavaScript. He attended the first RailsConf and the most recent PyCon US. He received an MBA and a BA in Computer Science and Spanish from Eastern Mennonite University. This article has been viewed 81,324 times.
How helpful is this?
Co-authors: 5
Updated: February 21, 2025
Views: 81,324
Categories: Python
Thanks to all authors for creating a page that has been read 81,324 times.

Is this article up to date?

Advertisement