Python | Comments

Python | Comments

In Python, Comments are used to explain or document code. They are ignored by the interpreter and do not affect the execution of the program.
There are two types of comment in Python:
1) single-line comments
2) multi-line comments

Single-line comment: This comment is start with the “#” symbol and continue until the end of the line.
For example:

# This is a single-line comment
x = 'ankit' 
#  x = 'rahul' 
# The above statement is also a single-line comment so this line ignored by the interpreter

Multi-line comment: This comment is also known as block comments, are used to comment out multiple lines of code at once. They start with a triple quotation mark (“””) and continue until the next triple quotation mark.
For example:

As you can see
this is a
multi-line comment

Another common way of writing multi-line comments is to use a single “#” symbol at the beginning of each line.

# This is a 
# multi-line comment

Note that using triple quotes is commonly used as a docstring also, which is a way of documenting the code (functions, classes, modules) and providing meta-information about the code.

Also, Python support inline comments using # , this is useful when you want to comment out a small piece of code and keep the rest of the code intact.

Leave a Reply

Your email address will not be published. Required fields are marked *

📢 Need further clarification or have any questions? Let's connect!

Connect 1:1 With Me: Schedule Call

If you have any doubts or would like to discuss anything related to this blog, feel free to reach out to me. I'm here to help! You can schedule a call by clicking on the above given link.
I'm looking forward to hearing from you and assisting you with any inquiries you may have. Your understanding and engagement are important to me!

This will close in 20 seconds