Comments in Python Programming

As all other programming languages, Python do supports multiple ways of adding comments to your code,

Comments in Python start with a # (hash) sign, all the lines in your code that start with # are ignored.

How to add a single line comment in Python

#This is my python code comment line.

How to place comment at the end of the line in Python?

print("Pyhton comments!") #This comment will be ignored

How to comment out code in Python?

You can simply add a # (hash) at the start of each statement to comment it out.

#print("I dont want this code")
print("I want this code")

How to add multi-line comment in Python?

Like Java we do not have a different syntax for muli-line comments in Python, one way is to add # at the start of each line.

# This is
# a multiline
# comment in 
# Python
print("Hello there!")

Another way of adding multiline comments is to enclose your comment with """ (3 double quotes - triple quotes)

This is
a multiline
comment in 
print("Hello there!")


  • My Python comments were not working, realized i was using slash instead of hash :D, thank you!
    user: anon 02 Oct 2020 11:01:11 GMT
  • Python comments block is what I was looking for.
    user: anon 02 Oct 2020 01:15:25 GMT
  • How to convert python comments to markdown class documentation?
    user: anon 01 Oct 2020 13:19:59 GMT
  • " python comments are useful and recommended!
    user: anon 28 Aug 2020 15:11:14 GMT
  • /** is not Pyhton style of comments.
    user: anon 27 Aug 2020 05:11:34 GMT
  • Further comments disabled!