1. Home
  2. Docs
  3. Python 101 – Python Programming for Beginners
  4. Commenting in python

Commenting in python

Commenting in python

Single line comment

For single line commenting # (pound) sign is used

# this is a single line comment and it will not get executed

# this is another line, which is commented

In Python files you usually see this line, which is part of the code,

but it only points Python interpreter path on Unix like systems. 

This line has not required if you running your Python program on Windows.

#!/user/bin/env python


Multiple line comment.

In Python multi-line or block commenting is done by using # (pound) sign on each line.

# This is the first line

# This is second line

# This is third line

# Comments continue


There is misconception about, people using triple quotes for commenting.

Actually triple quotes are used to represent multi-line string.


Double quotes, multi-line string.


this is first line

this is second  line

this is third  line

this is fourth line

this is fifth line

like this many lines can be added


Single quote multi-line string.


This is an example to show

how multi line string is added

to python file.


Using triple quotes for commenting is a bad practice, try avoiding it.

As comments are to briefly explain about code functionality.

Not to block a piece of  code form execution.

Multi line string block is also used to add to docstring to Python file.

docstring is short hand for documentation strings.

more on docstring in Functions in Python section.