How to Comment out Multiple Lines in Python?
You can comment out multiple lines in Python using the following methods:
1. Using #
for Each Line (Recommended)
pythonCopyEdit# This is a comment
# This is another comment
# This is yet another comment
2. Using Triple Quotes ("""
or '''
)
Although not technically a comment, Python treats triple-quoted strings as multi-line comments if they are not assigned to a variable.
pythonCopyEdit"""
This is a multi-line comment.
Python will ignore this unless assigned to a variable.
"""
or
pythonCopyEdit'''
Another multi-line comment example.
'''
3. Using an IDE Shortcut
- VS Code, PyCharm, Jupyter Notebook → Select lines and press
Ctrl + /
(Windows/Linux) orCmd + /
(Mac). - IDLE → No built-in shortcut, must use
#
manually.
For large sections, use #
for better readability and performance. 🚀