anne.dawson@gmail.com Python Comments --------------- Single line comments -------------------- Any lines in a Python program that start with the # symbol are known as comments. Comments are ignored when the program runs, but they're useful when we read a program, because they supply information about the program. Comments are always used at the top of a program to supply information about the purpose of a program, its file name (e.g. 00123456.py), the name of the programmer, the date last updated, the current status (completed, incomplete) and any other pertinent information. Comments are also used in the body of a program to explain parts of the program which may be hard for the reader to understand. Comments may be added to the end of any statement in a Python program by typing the # symbol first. Example programs in this course demonstrate the correct use of comments. Multi-line comments ------------------- As explained above, if you want to convert a line into a comment, simply type a # at the start of the line. If you have several lines to change into comments, you can place a # at the start of each line. To save on having to type a # at the start of multiple lines, there's another way to convert several lines of a program file into comments, ... Sometimes we need comments which span several lines in a program. As long as the block of statements starts and ends with the characters ''' (or """), those lines will be ignored by the Python interpreter (i.e. will NOT be executed). Multi-line comments are useful when you want to "comment out" a block of statements. Commenting out means to convert the statements into a comment so that they will not be executed. This is an alternative to deleting the statements. IMPORTANT NOTE ABOUT MULTI-LINE COMMENTS ---------------------------------------- Note that multi-line comments need to be indented within a while loop just like regular statements, but comments starting with the # character need not be indented. If you don't indent multi-line comments within a while loop you will get a syntax error. Try it! Documentation ------------- In the real world, programmers document each program that they write. This is because programmers work in teams and have to work on each other's programs. In its simplest form, documentation of a program includes the file name, programmer's name and date last updated in comments at the top of the code. As students of this programming course, you're expected to supply an appropriate set of comments for all of your lab and homework programming assignments.