Next-Gen App & Browser
Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles
Commenting multiple lines in Python helps make your code easier to understand, especially when you’re explaining logic or disabling code during testing. There are a few simple ways to do this:
The most commonly used method is adding the hash symbol (#) at the beginning of each line you want to comment out. It’s straightforward and works in every Python editor.
# This part of the code is commented out
# It's helpful for adding notes or disabling code
# without deleting it
print("Hello from Python!")
This method is ideal when you want to leave short notes or temporarily remove a block of code while testing.
Another approach is to wrap multiple lines in triple single quotes or triple double quotes. Python treats these as string literals, but if you don’t assign them to a variable, they won’t affect your code’s behavior.
This method is often used for documentation, but it can also work as a quick way to comment out multiple lines.
'''
This section is a multi-line comment
using single quotes. It's not assigned,
so Python ignores it.
'''
"""
You can also use double quotes
to do the same thing.
"""
print("Testing made easy!")
If you're using a code editor like VS Code, PyCharm, or even Jupyter Notebook, there's an easier way:
Windows/Linux: Select the lines and press Ctrl + /
Mac: Select the lines and press Cmd + /
This shortcut adds or removes #
automatically for all selected lines.
KaneAI - Testing Assistant
World’s first AI-Native E2E testing agent.