Commenting Code and Comment Tips

Comments are key to ensuring that your code is easy to follow and speeds up maintaining and checking.  There are two methods to creating comments in your code.

Line Comments

Line comments start with a harsh (#), this tells the python interpreter to skip over this line, continuing on the next line.

# Usefult comment here
print 'hello world!'

Block Comments

Block comments are initiated with three quotation marks in a row ("""), this tells the python interpreter to skip the code until it reaches three quotation marks in a row (""") again.


""" Many lines
of usefult comments
here """
print 'hello world!'

When commenting code it is import to include a useful amount of detail, too many or too few comments can both have negative impacts on readability.

Next - Using Variables




Related Sections

Python - Learn the python from the basics up. This fast track example code course will get you creating powerful python programs in no time.
Tkinter - Learn the key features of the tkinter to allow you to create user interfaces for your python programs.


Related Pages

Pickle - The pickle library allows a program to save data in a binary file.
Python - List Comprehension - Create powerful list comprehension expressions.
Python - Generators - Learn about generator statements.
Python - Data types - The learn about the key datatypes in the python language.
Tkinter - Combo Box - This is a short example showing how to use combo boxes in a GUI.
Tkinter - Radio Buttons - A short example of how to create a GUI with radio buttons.
Tkinter - Canvas - Canvas allows for a range of shapes to be plotted, such as circles, squares, lines