Python Comment | Creating a Comment | multiline comment | example

Python Comment | Creating a Comment | multiline comment | example

Python comment

Comments will be used to create a case for Python code.

Comments will be used to make the code more legible.

Once the code is tested, comments will not stop the execution.


Make a comment

Comments begin with #, and Python may ignore them:

Examples

# This can be a comment

Print (“Hello, World!”)

Comments will be placed at the top of a line, and Python may ignore the rest of the line:

Examples

Print (“Hello, World!”) # This could be a comment

Comments could not find the text to clarify the code, this may also be used to prevent Python from executing code:

Examples

#print (“Hello, World!”)

Print (“Cheers, Met!”)

Multi-line comments

Python does not have a syntax for multi-line comments.

To add a multi-line comment, you can insert a # for each line:

Examples

# This can be a comment # One line has # more written (“Hello, World!”

Or, almost as mean, you would use a multi-line string.

Since Python can ignore string literals that are not assigned to a variable, you will add a multi-line string (triple quotes) to your code, and you will comment within:


Examples

“””
This is a comment

written in

More than just one line

“””       

Print (“Hello, World!”)

Python can browse the code until the string is allocated to a variable, ignore it on the other side, and you have created a multi-line comment.

Related Python Post

Pramod Kumar Yadav is from Janakpur Dham, Nepal. He was born on December 23, 1994, and has one elder brother and two elder sisters. He completed his education at various schools and colleges in Nepal and completed a degree in Computer Science Engineering from MITS in Andhra Pradesh, India. Pramod has worked as the owner of RC Educational Foundation Pvt Ltd, a teacher, and an Educational Consultant, and is currently working as an Engineer and Digital Marketer.



Leave a Comment