Python Distilled, 1st edition

  • David M Beazley

$16.99per month

Minimum 4-month term, pay monthly or pay $67.96 upfront

Includes:

  • Instant access to eTextbook
  • Search, highlights, notes, and more
  • Expert video lessons and practice questions
  • Videos, study help in multiple subjects. List in FAQs.
  • Practice problems and study guides
  • Q&A with experts and AI tutor
14-day refund guarantee

$10.99per month

Minimum 4-month term, pay monthly or pay $43.96 upfront

Includes:

  • Instant access to eTextbook
  • Search, highlights, notes, and more
14-day refund guarantee

$16.99per month

Minimum 4-month term, pay monthly or pay $67.96 upfront

Includes:

  • Instant access to eTextbook
  • Search, highlights, notes, and more
  • Expert video lessons and practice questions
  • Videos, study help in multiple subjects. List in FAQs.
  • Practice problems and study guides
  • Q&A with experts and AI tutor
14-day refund guarantee

$10.99per month

Minimum 4-month term, pay monthly or pay $43.96 upfront

Includes:

  • Instant access to eTextbook
  • Search, highlights, notes, and more
14-day refund guarantee

$10.99per month

Minimum 4-month term, pay monthly or pay $43.96 upfront

Includes:

  • Instant access to eTextbook
  • Search, highlights, notes, and more
14-day refund guarantee

$10.99per month

Minimum 4-month term, pay monthly or pay $43.96 upfront

Includes:

  • Instant access to eTextbook
  • Search, highlights, notes, and more
14-day refund guarantee

Learn more, spend less

  • Find it fast

    Quickly navigate your eTextbook with search

  • Stay organized

    Access all your eTextbooks in one place

  • Easily continue access

    Keep learning with auto-renew

Overview

Preface xiii

Chapter 1: Python Basics 1
1.1 Running Python 1
1.2 Python Programs 2
1.3 Primitives, Variables, and Expressions 3
1.4 Arithmetic Operators 5
1.5 Conditionals and Control Flow 7
1.6 Text Strings 9
1.7 File Input and Output 12
1.8 Lists 13
1.9 Tuples 15
1.10 Sets 17
1.11 Dictionaries 18
1.12 Iteration and Looping 21
1.13 Functions 22
1.14 Exceptions 24
1.15 Program Termination 26
1.16 Objects and Classes 26
1.17 Modules 30
1.18 Script Writing 32
1.19 Packages 33
1.20 Structuring an Application 34
1.21 Managing Third-Party Packages 35
1.22 Python: It Fits Your Brain 36

Chapter 2: Operators, Expressions, and Data Manipulation 37
2.1 Literals 37
2.2 Expressions and Locations 38
2.3 Standard Operators 39
2.4 In-Place Assignment 41
2.5 Object Comparison 42
2.6 Ordered Comparison Operators 42
2.7 Boolean Expressions and Truth Values 43
2.8 Conditional Expressions 44
2.9 Operations Involving Iterables 45
2.10 Operations on Sequences 47
2.11 Operations on Mutable Sequences 49
2.12 Operations on Sets 50
2.13 Operations on Mappings 51
2.14 List, Set, and Dictionary Comprehensions 52
2.15 Generator Expressions 54
2.16 The Attribute (.) Operator 56
2.17 The Function Call () Operator 56
2.18 Order of Evaluation 56
2.19 Final Words: The Secret Life of Data 58

Chapter 3: Program Structure and Control Flow 59
3.1 Program Structure and Execution 59
3.2 Conditional Execution 59
3.3 Loops and Iteration 60
3.4 Exceptions 64
3.5 Context Managers and the with Statement 75
3.6 Assertions and __debug__ 77
3.7 Final Words 78

Chapter 4: Objects, Types, and Protocols 79
4.1 Essential Concepts 79
4.2 Object Identity and Type 80
4.3 Reference Counting and Garbage Collection 81
4.4 References and Copies 83
4.5 Object Representation and Printing 84
4.6 First-Class Objects 85
4.7 Using None for Optional or Missing Data 87
4.8 Object Protocols and Data Abstraction 87
4.9 Object Protocol 89
4.10 Number Protocol 90
4.11 Comparison Protocol 92
4.12 Conversion Protocols 94
4.13 Container Protocol 95
4.14 Iteration Protocol 97
4.15 Attribute Protocol 98
4.16 Function Protocol 98
4.17 Context Manager Protocol 99
4.18 Final Words: On Being Pythonic 99

Chapter 5: Functions 101
5.1 Function Definitions 101
5.2 Default Arguments 101
5.3 Variadic Arguments 102
5.4 Keyword Arguments 103
5.5 Variadic Keyword Arguments 104
5.6 Functions Accepting All Inputs 104
5.7 Positional-Only Arguments 105
5.8 Names, Documentation Strings, and Type Hints 106
5.9 Function Application and Parameter Passing 107
5.10 Return Values 109
5.11 Error Handling 110
5.12 Scoping Rules 111
5.13 Recursion 114
5.14 The lambda Expression 114
5.15 Higher-Order Functions 115
5.16 Argument Passing in Callback Functions 118
5.17 Returning Results from Callbacks 121
5.18 Decorators 124
5.19 Map, Filter, and Reduce 127
5.20 Function Introspection, Attributes, and Signatures 129
5.21 Environment Inspection 131
5.22 Dynamic Code Execution and Creation 133
5.23 Asynchronous Functions and await 135
5.24 Final Words: Thoughts on Functions and Composition 137

Chapter 6: Generators 139
6.1 Generators and yield 139
6.2 Restartable Generators 142
6.3 Generator Delegation 142
6.4 Using Generators in Practice 144
6.5 Enhanced Generators and yield Expressions 146
6.6 Applications of Enhanced Generators 148
6.7 Generators and the Bridge to Awaiting 151
6.8 Final Words: A Brief History of Generators and Looking Forward 152

Chapter 7: Classes and Object-Oriented Programming 153
7.1 Objects 153
7.2 The class Statement 154
7.3 Instances 155
7.4 Attribute Access 156
7.5 Scoping Rules 158
7.6 Operator Overloading and Protocols 159
7.7 Inheritance 160
7.8 Avoiding Inheritance via Composition 163
7.9 Avoiding Inheritance via Functions 166
7.10 Dynamic Binding and Duck Typing 167
7.11 The Danger of Inheriting from Built-in Types 167
7.12 Class Variables and Methods 169
7.13 Static Methods 173
7.14 A Word about Design Patterns 176
7.15 Data Encapsulation and Private Attributes 176
7.16 Type Hinting 179
7.17 Properties 180
7.18 Types, Interfaces, and Abstract Base Classes 183
7.19 Multiple Inheritance, Interfaces, and Mixins 187
7.20 Type-Based Dispatch 193
7.21 Class Decorators 194
7.22 Supervised Inheritance 197
7.23 The Object Life Cycle and Memory Management 199
7.24 Weak References 204
7.25 Internal Object Representation and Attribute Binding 206
7.26 Proxies, Wrappers, and Delegation 208
7.27 Reducing Memory Use with __slots__ 210
7.28 Descriptors 211
7.29 Class Definition Process 215
7.30 Dynamic Class Creation 216
7.31 Metaclasses 217
7.32 Built-in Objects for Instances and Classes 222
7.33 Final Words: Keep It Simple 223

Chapter 8: Modules and Packages 225
8.1 Modules and the import Statement 225
8.2 Module Caching 227
8.3 Importing Selected Names from a Module 228
8.4 Circular Imports 230
8.5 Module Reloading and Unloading 232
8.6 Module Compilation 233
8.7 The Module Search Path 234
8.8 Execution as the Main Program 234
8.9 Packages 235
8.10 Imports Within a Package 237
8.11 Running a Package Submodule as a Script 238
8.12 Controlling the Package Namespace 239
8.13 Controlling Package Exports 240
8.14 Package Data 241
8.15 Module Objects 242
8.16 Deploying Python Packages 243
8.17 The Penultimate Word: Start with a Package 244
8.18 The Final Word: Keep It Simple 245

Chapter 9: Input and Output 247
9.1 Data Representation 247
9.2 Text Encoding and Decoding 248
9.3 Text and Byte Formatting 250
9.4 Reading Command-Line Options 254
9.5 Environment Variables 256
9.6 Files and File Objects 256
9.7 I/O Abstraction Layers 260
9.8 Standard Input, Output, and Error 263
9.9 Directories 264
9.10 The print() function 265
9.11 Generating Output 265
9.12 Consuming Input 266
9.13 Object Serialization 268
9.14 Blocking Operations and Concurrency 269
9.15 Standard Library Modules 273
9.16 Final Words 296

Chapter 10: Built-in Functions and Standard Library 297
10.1 Built-in Functions 297
10.2 Built-in Exceptions 314
10.3 Standard Library 318
10.4 Final Words: Use the Built-Ins 320

Index 321

Published by Addison-Wesley Professional (December 15th 2021) - Copyright © 2022

ISBN-13: 9780137665655

Subject: Programming - Introductory

Category: Python

Your questions answered

Pearson+ is your 1-stop shop with eTextbooks, study tools and exam prep features designed to help students get better grades in college. eTextbooks come with built-in tools that simplify studying, like flashcards, audiobook and search. Pearson+ also features Channels, which includes practice problems, study guides, Q&A with experts, video lessons that help you understand tricky topics and more—all in one place. Channels can be purchased separately or added on to your eTextbook at the time of purchase as part of the Study & Exam Prep Pack.

A Pearson eTextbook is an easy-to-use digital version of your book for class that includes upgraded study tools to help you learn how you learn best. Use enhanced search to find what you need within your eTextbook, highlight and make notes to mark important info, generate flashcards to test your knowledge, and use audio to listen to the text. Every feature is designed to help you learn more efficiently and get results. Plus, you can learn on the go with the Pearson+ app. Find this and more in your eTextbook, available in Pearson+.

The Study & Exam Prep Pack includes practice problems, study guides, Q&A with experts, Channels video lessons that help you understand tricky topics and more. It can be added on to your eTextbook or your MyLab and Mastering learning platform at the time of purchase.

Your eTextbook subscription gives you access for 4 months. You can make a one‑time payment for the initial 4‑month term or pay monthly. If you opt for monthly payments, we will charge your payment method each month until your 4‑month term ends. You can turn on auto‑renew in My account at any time to continue your subscription before your 4‑month term ends.

When you purchase an eTextbook subscription, it will last 4 months. You can renew your subscription by selecting Extend subscription on the Manage subscription page in My account before your initial term ends.

If you extend your subscription, we'll automatically charge you every month. If you made a one‑time payment for your initial 4‑month term, you'll now pay monthly. To make sure your learning is uninterrupted, please check your card details.

To avoid the next payment charge, select Cancel subscription on the Manage subscription page in My account before the renewal date. You can subscribe again in the future by purchasing another eTextbook subscription.

Channels is a video platform with thousands of explanations, solutions and practice problems to help you do homework and prep for exams. Videos are personalized to your course, and tutors walk you through solutions. Plus, interactive AI‑powered summaries and a social community help you better understand lessons from class.

Channels is an additional tool to help you with your studies. This means you can use Channels even if your course uses a non‑Pearson textbook.

When you choose a Channels subscription, you're signing up for a 1‑month, 3‑month or 12‑month term and you make an upfront payment for your subscription. By default, these subscriptions auto‑renew at the frequency you select during checkout.

When you purchase a Channels subscription it will last 1 month, 3 months or 12 months, depending on the plan you chose. Your subscription will automatically renew at the end of your term unless you cancel it.

We use your credit card to renew your subscription automatically. To make sure your learning is uninterrupted, please check your card details.

A Study & Exam Prep subscription includes video lessons, practice problems and other study tools. Get unlimited access to the full range of subjects:

  • General Chemistry
  • Physics
  • General Biology
  • Financial Accounting
  • Psychology
  • Microeconomics
  • Anatomy & Physiology
  • College Algebra
  • Organic Chemistry
  • Genetics
  • GOB Chemistry
  • Intro to Chemistry
  • Microbiology
  • Cell Biolog
  • Analytical Chemistry
  • Trigonometry
  • Precalculus
  • Biochemistry
  • Macroeconomics
  • Yes, the Study & Exam Prep Pack's feature is Channels, which can be purchased separately at any time. Simply go to Channels on the Pearson+ site and choose monthly, quarterly, or annual access, separate from your eTextbook subscription. Still deciding? Watch the first six videos free and buy it if you love it (we know you'll love it!).

    Currently, they are the exact same offering. 'Study & Exam Prep Pack' is what we call 'Channels' when it is bundled with an eTextbook or bundled with MyLab & Mastering courseware. When purchased on its own, you will see it called Channels, still the same study & exam prep help you need.