Page 57 -
P. 57

meet python




                             Here’s a copy of the current list-processing code. Your task is to rewrite this code using an if
                             statement and the isinstance() BIF to process a list that displays another list.



                                                     for each_item in movies:
                                                           print(each_item)




                               Write your
                               new code
                                here.



























           Q:   Are there many of these BIFs in   Q:  How?                  Q:   Why so many BIFs?

           Python?
                                           A: At the Python or IDLE shell, type   A: Why not? Because Python comes with
          A: Yes. At the last count, there were over   dir(__builtins__) to see a list   lots of built-in functionality, it can mean less
           70 BIFs in Python 3.            of the built-in stuff that comes with Python   code for you to write. This Python philosophy
           Q:   Over 70! How am I to remember   (that’s two leading and trailing underscore   enough included with Python to let you do
                                                                            is known as “batteries included”: there’s
                                           characters, by the way). The shell spits
           that many, let alone find out what they all   out a big list. Try it. All those lowercase   most things well, without having to rely on
           are?                             words are BIFs. To find out what any BIF   code from third parties to get going. As well
                                           does—like input(), for example—type   as lots of BIFs, you’ll find that Python’s
          A: You don’t have to worry about   help(input) at the shell for a   standard library is rich and packed with
                                                                            features waiting to be exploited by you.
           remembering. Let Python do it for you.  description of the BIFs function.

                                                                                       you are here 4    21
   52   53   54   55   56   57   58   59   60   61   62