How to add comments to Python code

Comment in Python

Everything to the right of # is ignored.


# Print the circumference of the circle: 
print 2 * 3.14 * 4
#   w  ww  .j a  v  a  2  s.c  o  m
 
#
# This is 
# a comment.

print "coment is inside #"

The code above generates the following result.

A comment on the same line as code.


print 2+2  # A comment on the same line as code

The code above generates the following result.





















Home »
  Python »
    Language Basics »




Python Basics
Operator
Statements
Function Definition
Class
Buildin Functions
Buildin Modules