Skip to main content

4.5) Comments


Even if Python is relatively easy to read compared to other languages, if you don't put comments throughout your code, months later when you come to look at your program again, you won't remember what your code does and why you wrote it. It might take longer to write properly documented code, but believe me, it is very important in the long-run and will save you hours, days or even weeks later on; efficient programmers document their code!

You might also like to share your code with others, so commenting your code will be even more crucial.

In Python, comments are inserted in code using #. You can try it out in the interpreter:

>>> # this is a line of comment
>>> print "Hello, World!"   # this will print out some text

Anything that come after # will be ignored by Python. So if you were to start a command line with #, nothing will happen.

>>> # print "Hello, World!"
>>>