
What are comments
Like other programming languages, Python also support commenting codes. Comments are not read or executed as part of the program, rather they are used to add notes / explanation in code.
Single-line comment in Python
Just add # at the beginning of the line.
Example
# This is a comment line.
print("Ravi Shekhar") # we can also add comment after code.
Multiple-lines comments in Python
There are two ways you can write multiple lines codes.
- Put # at the start of every line.
- Using triple quotes.
How to use triple quotes for multiple lines comments
Just wrap your comment inside a set of triple quotes.
"""
This is first line of multiple lines comment.
This is another comment line.
This is third comment line.
"""
'''
This is first line of multiple lines comment.
This is another comment line.
This is third comment line.
'''
How to add # at the start of multiple lines by one click
Select the lines that you want to comment (add # at the start of the line) and press:
- On Windows: Ctrl + /
- On Mac: cmd + /
I hope this python tutorial was helpful to you.
Category