Python comments

Comment in Python is a piece of code that is not interpreted by Python. Comments in Python or in any other programming language are used to give some additional information about a certain block of code. The main purpose of comments is to let others understand what a certain block of code does. So that they can modify it in the future if required.


Creating a Python Comment

In Python, a comment starts with a # symbol. Python does not interpret a line that starts with the # symbol. Therefore comments are not part of any output.

# Hi, I am a comment.
print('Hello, I am not a comment')

Output:

Hello, I am not a comment

An inline comment in Python

A comment can also be placed in the same line as the executable code. The Python interpreter will skip the execution of the code that is placed after the # symbol. See the below example:

print('Hello, Print me!!')    # This is an inline comment

Output:

Hello, Print me!!

Creating multi line comments

Python does not provide us with a separate syntax for creating multi-line comments as other programming languages do. However, we can use the # symbol to create multi-line comments. See the below example:

# Hello,
# I am a 
# multi-line comment.
print('I am not a comment')

Output:

I am not a comment

Author

  • Manoj Kumar

    Hi, My name is Manoj Kumar. I am a full-stack developer with a passion for creating robust and efficient web applications. I have hands-on experience with a diverse set of technologies, including but not limited to HTML, CSS, JavaScript, TypeScript, Angular, Node.js, Express, React, and MongoDB.