top of page

[Python] Commenting Out Multiple Lines

  • 1 day ago
  • 1 min read

Writing comments across multiple lines is needed for annotating source code, and for temporarily disabling processing during development and testing.

Commenting out a single line

To comment out just one line, use "#" (hash)

print("Good morning!")
# print("This line is commented out and will not run")
print("Good afternoon!") #You can also put a comment after a command
print("Good night!")

The result is as follows. The commented-out part doesn't run, so it isn't printed.

Good morning!
Good afternoon!
Good night!

Commenting out multiple lines

To comment out multiple lines, wrap the target code in triple quotes. Triple quotes can be either """ (three double quotation marks) or ''' (three single quotation marks).

print("Good morning!")
'''
print("This line is commented out and will not run")
print("Good afternoon!") #You can also put a comment after a command
'''
print("Good night!")

The result is as follows. The commented-out part doesn't run, so it isn't printed.

Good morning!
Good night!
 
 
 

Comments


© Copyright ROBIN planning LLC.

​Privacy Policy

​Disclaimer

bottom of page