Every programming language has comment options syntax. It’s needed because the application has a lot of coding and multiplayer in a team. Here we will discuss Python comments on Single line and multiline with comment syntax.
- Single line python comments are created simply by beginning a line with the hash (#) character and automatically finished at the end of the line.
- For a Multiple line comment use adding a delimiter (” ” “) on each start and end of the comment.
Let’s See the examples and syntax of a single line, multiline, block and inline comments in python.
Comments Block Syntax
A very simple python comment syntax.
#I am comment in Python
python block comment Examples :
Use Hash # for single-line comments. A simple example for “Hello world program”
# Print “Hello, World!” to console print("Hello, World!")
Output: Hello, World!
# Define color variable as a list of strings color = ['red', 'green', 'yellow', 'pink', 'white', 'black'] # For loop that iterates over color list and prints each string item for c in color: print(c)
Multiline Comment Syntax
Here is syntax, how you can do multiple line comments in python.
""" Hello coder i am multiple line comment in python """
Python block comment Example :
Use triple-quoted strings to multiple line comments. Here are the code screenshot and code example below.
""" This is a "block comment" in Python, made out of a multi line string constant. it will print number. """ count = 2 print(count)
Output : 2
Python Block Comments
Python blocks comments, each line begins with the hash mark and a single space. You can use more than one paragraph, they must be separated by a line that contains a single hash mark #.
Example and Syntax
# long comment # here. print("Hello, World!")
Inline Comments Python
End of the code line you can put the comment, followed by hash #, same as other comments. Inline comments begin with a hash mark and a single whitespace character and end with itself the end of a line.
Example and Syntax
print("Hello, World!") # Print hello world
That’s all about a “Python Block Comment” if you have in doubt and suggestion, then do comment in below.
Note : This example (Project) is developed in PyCharm 2018.2 (Community Edition)
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
All Python Comments Example & Python multiline comment Syntax are in Python 3, so it may change its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.