Next-Gen App & Browser
Testing Cloud

Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Next-Gen App & Browser Testing Cloud

How to Comment Multiple Lines in Python?

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:

  • Add # to Each Line
  • 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.


  • Use Triple Quotes (''' or """)
  • 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!")

  • Try Editor Shortcuts
  • 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.

Test Your Website on 3000+ Browsers

Get 100 minutes of automation test minutes FREE!!

Test Now...

KaneAI - Testing Assistant

World’s first AI-Native E2E testing agent.

...
ShadowLT Logo

Start your journey with LambdaTest

Get 100 minutes of automation test minutes FREE!!

Signup for free