how to comment out multiple lines in python code example
Example 1: python if statement multiple lines
# ex. 1
if (cond1 == 'val1' and cond2 == 'val2' and
cond3 == 'val3' and cond4 == 'val4'):
do_something
# Also, don't forget the whitespace is more flexible than you might think:
# ex. 2
if (
cond1 == 'val1' and cond2 == 'val2' and
cond3 == 'val3' and cond4 == 'val4'
):
do_something
if (cond1 == 'val1' and cond2 == 'val2' and
cond3 == 'val3' and cond4 == 'val4'):
do_something
Example 2: multiline comment python
# While Python doesn't support multi-line comments, it can ignore anything
'''
inside a multi-line string!
Just wrap the comment in the three single quote marks,
And
you're
good
to
go!
'''
Example 3: python comment multiple lines
#There is no way to comment multiple lines in Python.
#You just keep using "#" symbol to comment each line out.
'''
Technically you could also use triple single quotation
marks like so, but this formatting does not count
as "true" source code comments that are removed by
a Python parser.
'''
Example 4: python big comment
# one hashtag for a single line comment
"""
3 quote marks is technically
a docstring, but it works as
a multi line comment
"""
##pressing 'Alt 3' in IDLE comments out
##what you are selecting
and 'Alt 4' to uncomment
if False:
print('Hello') # yes you can do it at the end of a line
you can technically put if False around code you dont want it to run,
but that would mean it has to have correct syntax,
and would not be good for readability.
Example 5: multiline comment python
# Python doesn't support multi-line comment blocks out of the box.
# The recommended way to comment out multiple lines of code in Python is
# to use consecutive single-line comments.
# feelsbadman
Example 6: python multiline comment
#%% There are not multiline comments in python,
# this # is the only form of commenting but, people use
# """triple quotes""" for multiline commenting but this
# is actually a String the interpreter will read and
# will ocupy memory. If you dont put this kind of string
# into a variable it will be collected on execution