Page 90 -
P. 90

who did what





                                                                         SOLUTION


                            You were to use your pencil to draw a line matching each BIF to the correct
                            description. Once you had all your lines drawn, you were to circle the BIF
                            you think you need to use in the next version of your function.


                     BIF                                    What the BIF does


                     list()                                 Creates a numbered list of paired-data, starting
                                                            from 0.


                     range()                                Returns the unique identification for a Python
                                                            data object.
           This BIF
            looks
            interesting.  enumerate()                       A factory function that creates a new, empty list.




                     int()                                  Returns the next item from a iterable data
                                                            structure such as a list.



                     id()                                   Returns an iterator that generates numbers in a
                                                            specified range on demand and as needed.



                     next()                                 Converts a string or another number to an
                                                            integer (if possible).



          The range() BIF iterates a fixed number of times

           The range() BIF gives you the control you need to iterate a specific
           number of times and can be used to generate a list of numbers from zero up-
           to-but-not-including some number. Here’s how to use it:             Generate numbers up-to-
                                                                               but-not-including 4.
              “num” is the target identifier
               and is assigned each of the     for num in range(4):
               numbers generated by “range()”      print(num)
               in turn.                                                          The numbers 0, 1, 2, and 3 will
                                                                                 appear on screen.

           54    Chapter 2
   85   86   87   88   89   90   91   92   93   94   95