Page 11 - Python Basics: A Practical Introduction to Python 3
P. 11

Contents


               8.4   Challenge: Find the Factors of a Number . . . . . . . 206
               8.5   Break Out of the Pattern . . . . . . . . . . . . . . . 207
               8.6   Recover From Errors . . . . . . . . . . . . . . . . . 211
               8.7   Simulate Events and Calculate Probabilities . . . . . 217
               8.8   Challenge: Simulate a Coin Toss Experiment . . . . . 223
               8.9   Challenge: Simulate an Election . . . . . . . . . . . 223
               8.10 Summary and Additional Resources . . . . . . . . . 224

            9  Tuples, Lists, and Dictionaries                           226
               9.1   Tuples Are Immutable Sequences . . . . . . . . . . . 227
               9.2   Lists Are Mutable Sequences . . . . . . . . . . . . . 237
               9.3   Nesting, Copying, and Sorting Tuples and Lists  . . . 251
               9.4   Challenge: List of lists . . . . . . . . . . . . . . . . . 257
               9.5   Challenge: Wax Poetic . . . . . . . . . . . . . . . . 258
               9.6   Store Relationships in Dictionaries . . . . . . . . . . 260
               9.7   Challenge: Capital City Loop . . . . . . . . . . . . . 270
               9.8   How to Pick a Data Structure . . . . . . . . . . . . . 272
               9.9   Challenge: Cats With Hats . . . . . . . . . . . . . . 273
               9.10 Summary and Additional Resources . . . . . . . . . 274


            10 Object-Oriented Programming (OOP)                         276
               10.1 Define a Class . . . . . . . . . . . . . . . . . . . . . 277
               10.2 Instantiate an Object . . . . . . . . . . . . . . . . . 281
               10.3 Inherit From Other Classes . . . . . . . . . . . . . . 287
               10.4 Challenge: Model a Farm . . . . . . . . . . . . . . . 296
               10.5 Summary and Additional Resources . . . . . . . . . 297

            11 Modules and Packages                                      298
               11.1  Working With Modules . . . . . . . . . . . . . . . . 299
               11.2 Working With Packages . . . . . . . . . . . . . . . . 310
               11.3 Summary and Additional Resources . . . . . . . . . 318

            12 File Input and Output                                     320
               12.1 Files and the File System . . . . . . . . . . . . . . . 321
               12.2 Working With File Paths in Python . . . . . . . . . . 324
               12.3 Common File System Operations . . . . . . . . . . . 333
               12.4 Challenge: Move All Image Files to a New Directory . 350



                                                                          10
   6   7   8   9   10   11   12   13   14   15   16