Page 17 -
P. 17

table of contents


                                     custom data objects
                           6         Bundling code with data



                                     It’s important to match your data structure choice to your data.
                                     And that choice can make a big difference to the complexity of your code. In Python,
                                     although really useful, lists and sets aren’t the only game in town. The Python dictionary
                                     lets you organize your data for speedy lookup by associating your data with names, not
                                     numbers. And when Python’s built-in data structures don’t quite cut it, the Python class
                                     statement lets you define your own. This chapter shows you how.


                                                  Coach Kelly is back (with a new file format)       174
                                                  Use a dictionary to associate data                 178
                                                  Bundle your code and its data in a class           189
                                                  Define a class                                     190
                                                  Use class to define classes                        191
                                                  The importance of self                             192
                                                  Every method’s first argument is self              193
                                                  Inherit from Python’s built-in list                204
                                                  Coach Kelly is impressed                           211
                                                  Your Python Toolbox                                212















                    The Object
                      Factory













                                                                                                        xv
   12   13   14   15   16   17   18   19   20   21   22