Quickly turn multiple lines into comments in Python
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 fact-checked, ensuring the accuracy of any cited facts and confirming the authority of its sources.
This article has been viewed 73,130 times.
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.
Steps
Community Q&A
-
QuestionHow to apply # on all lines of code?BhoimusTop AnswererFirst, 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.
Video
Tips
-
Keep Python regularly updated. You can check what version you’re using with the Python command line.Thanks
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.