Question: How can one comment out multiple lines in Python?
Answer: In Python, you can comment out multiple lines by using triple quotes (either single or double) as a multiline comment. This method is often employed for adding block comments or temporarily disabling a block of code.
Example with explanation:
python'''
This is a multiline comment in Python.
You can write multiple lines of comments
within triple-quotes to provide explanations
or temporarily disable a block of code.
'''
# Alternatively, you can use triple double-quotes:
"""
This is another example of a multiline comment.
It serves the same purpose as the single-quoted version.
"""
# Code outside the triple-quotes will be executed normally.
print("Hello, World!")
In the above example, the lines enclosed within triple quotes (''') are treated as comments and won't be executed. This is a handy way to document your code or temporarily exclude certain sections during testing or debugging.
0 মন্তব্যসমূহ