Page 74 -
P. 74

request for comments




                                              Here is your module code (which is saved in the file nester.py). In
                                              the spaces provided, you were asked to use your pencil to compose
                                              two comments: the first to describe the module and the second to
                                              describe the function.


                           “““This is the “nester.py" module, and it provides one function called
                            print_lol() which prints lists that may or may not include nested lists.”””

             Did you
              remember to   def print_lol(the_list):
              include the triple   “““This function takes a positional argument called “the_list", which is any
              quotes?              Python list (of, possibly, nested lists). Each data item in the provided list

                                   is (recursively) printed to the screen on its own line.”””

                                   for each_item in the_list:
                                          if isinstance(each_item, list):
                                                                               There are no changes to the
                                                 print_lol(each_item)
                                          else:                                actual code here; you’re just
                                                 print(each_item)              adding some comments.







           Q:   How do I know where the Python   Q:  Does it matter where I put my   Q:  Is there any other way to add a

           modules are on my computer?     nester.py module?                comment to Python code?


          A: Ask IDLE. Type import sys;  A: For now, no. Just be sure to put it   A: Yes. If you put a “#” symbol anywhere
           sys.path (all on one line) into the IDLE   somewhere where you can find it later. In   on a line, everything from that point to the
           prompt to see the list of locations that your   a while, you’ll install your module into your   end of the current line is a comment (unless
           Python interpreter searches for modules.  local copy of Python, so that the interpreter   the “#” appears within a triple quote, in
           Q:   Hang on a second. I can use “;” to   can find it without you having to remember   of Python programmers use the “#” symbol
                                                                            which case it’s part of that comment). A lot
                                            when you actually put it.
           put more than one line of code on the   Q:                       to quickly switch on and off a single line of
           same line in my Python programs?      So comments are like a funny-  code when testing new functionality.
                                            looking string surrounded by quotes?
          A: Yes, you can. However, I don’t
           recommend that you do so. Better to give  A: Yes. When a triple-quoted string is
           each Python statement its own line; it makes   not assigned to a variable, it’s treated like a
           your code much easier for you (and others)   comment. The comments in your code are
           to read.                        surrounded by three double quotes, but you
                                           could have used single quotes, too.
           38    Chapter 2
   69   70   71   72   73   74   75   76   77   78   79