How to declare comments in python?

Python Comments

Comments are very important while writing a program. They describe what is going on inside a program, so that a person looking at the source code does not have a hard time figuring it out.
In Python, we use the hash (#) symbol to start writing a comment.

Multi-line comments

Another way of doing this is to use triple quotes, either ''' or """.

These triple quotes are generally used for multi-line strings. But they can be used as a multi-line comment as well.

"""This is also a
perfect example of
multi-line comments"""

Docstrings in Python

A docstring is short for documentation string. Python docstrings (documentation strings) are the string literals that appear right after the definition of a function, method, class, or module. Triple quotes are used while writing docstrings. For example:

def double(num):
"""Function to double the value"""
return 10*num

Example

#This is a comment
print("Hello, Sana Mahtab!")

Example

#print("Hello, Sana!")
print("Mahira, Mahtab!")

Multiline Comments :-

"""
This is a Multiline comment
written in
more than just one line
"""
print("Hello, Python!")





Previous Next


Trending Tutorials




Review & Rating

0.0 / 5

0 Review

5
(0)

4
(0)

3
(0)

2
(0)

1
(0)

Write Review Here