Skip to content

Python Comments Block Syntax | Multiline Comment with Examples

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.
Python Comments Block Syntax | Multiline Comment with Examples

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!

In a for loop that iterates over a list, comments will look like this example.

# 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:

Output: red

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.

Python Multiline Comment Example
This is a "block comment" in Python, made
out of a multi line string constant.
it will print number.
count = 2

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)
JRE: 1.8.0
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.6

Python 3.7

All Python Comments Example & Python multiline comment Syntax are in Python 3, so it may change its different from python 2 or upgraded versions.

3 thoughts on “Python Comments Block Syntax | Multiline Comment with Examples”

  1. THANK

    I was using Microsoft’s Code editor working on a program that would read files, do some reformatting and testing, write ’em back out. I copied samples of the file so I could more easily see what I’m dealing with, and it included a line that had %% at the beginning, which I commented out with a #, and the editor thought it was a Jupyter directive!

    I don’t have a clue what Jupyter is! I’m sure it’s quite nifty, but I have absolutely no need for the little piddly stuff that I’m doing right now. There’s probably some way to disable it, but I don’t know how. I use block quotes around the sample lines, and all is well.


    BTW, I use in-line comments all the time. I’ve been coding for over 3 decades, but I’m new to Python and it’s a bit different. My normal profession was relational database and server admin, but I consider myself semi-retired and this is just for my own fun, edification, and utility. Now I work in a library, and quite enjoy a mostly non-stress job.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading