python comments


Python code can be explained by comments.

Comments may be used for the readability of the code.

Comments may be employed when testing code to prevent execution.

You can also search for these topics, python comments examples, python comments start with symbol and syntax, what are python comments, what is the use of python in comments, what are type of python in comments, what is comment how to apply comment in python.

Creating a Comment

Python ignores comments that begin with a # :

Example 1 :-

#This is a comment.
print("Hello, World!")

Output :-

Hello, World!

Python will disregard the remainder of the line if you put a comment at the end of a line :

Example 2 :-

print("Hello, World!") #This is a comment.

Output :-

Hello, World!

It's not necessary for a comment to be text that explains the code; it can also be used to Prevention Python from running code.

Example 3 :-

#print("Hello, World!")
print("Cheers, Mate!")

Output :-

Cheers, Mate!

You can also search for these topics, python generate a comment, python adding comments, python create comment block, how to create a comment in python, python how to make a comment, python comment line, python single line comment, python comment syntax and shortcut.

Multi Line Comments

The syntax for multi-line comments is not really available in Python.

To add a multiline comment, use # for each line :

Example 1 :-

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

Output :-

Hello, World!

You can also make use of a multiline string, which is not exactly what was intended.

As the literal strings the variable has not been assigned to are ignored by Python, you can insert a many-line string (three quotes) into your code.

Example 2 :-

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

Output :-

Hello, World!

Until the string is assigned to a variable, Python will read, ignore, but have made multiline comments about the code.

You can also search for these topics, python multi line comment syntax, python multiline comment not working, block, style and shortcut, what is used for multiline comment in python, how to declare multiline comment in python, how to remove multiline comment in python, how to give multiline comment in python, how to do multiline comment in python.