Index
Symbols
- != (not equal to) operator, Rich Comparison Operators
- !r conversion field, String Representation
- % (modulo) operator, What’s New in This Chapter, String Representation
- %r placeholder, String Representation
- * (star) operator, Emulating Numeric Types, Using * to Grab Excess Items-Unpacking with * in Function Calls and Sequence Literals, Using + and * with Sequences-A += Assignment Puzzler, From Positional to Keyword-Only Parameters, Overloading * for Scalar Multiplication-Overloading * for Scalar Multiplication
- ** (double star) operator, Unpacking Mappings, From Positional to Keyword-Only Parameters
- *= (star equals) operator, Augmented Assignment with Sequences-A += Assignment Puzzler, Augmented Assignment Operators-Augmented Assignment Operators
- *_ symbol, Pattern Matching with Sequences
- *_new*_, Flexible Object Creation with __new__-Flexible Object Creation with __new__
- + operator, Emulating Numeric Types, Using + and * with Sequences-A += Assignment Puzzler, Overloading + for Vector Addition-Overloading + for Vector Addition
- += (addition assignment) operator, Augmented Assignment with Sequences-A += Assignment Puzzler, Augmented Assignment Operators-Augmented Assignment Operators
- +ELLIPSIS directive, A Pythonic Card Deck
- := (Walrus operator), List Comprehensions and Readability
- < (less than) operator, Rich Comparison Operators
- <= (less than or equal to) operator, Rich Comparison Operators
- == (equality) operator, Identity, Equality, and Aliases, Further Reading, Rich Comparison Operators
- > (greater than) operator, Rich Comparison Operators
- >= (greater than or equal to) operator, Rich Comparison Operators
- @ sign, Using @ as an Infix Operator-Using @ as an Infix Operator
- @asyncio.coroutine decorator, A Few Definitions
- @cached_property, Step 5: Caching Properties with functools
- @contextmanager decorator, Using @contextmanager-Using @contextmanager
- @dataclass
- @typing.overload decorator, Overloaded Signatures-Takeaways from Overloading max
- [] (square brackets), A Pythonic Card Deck, List Comprehensions and Readability, Unpacking Sequences and Iterables, Multidimensional Slicing and Ellipsis
- \ (backslash), List Comprehensions and Readability
- \ line continuation escape, List Comprehensions and Readability
- \N{} (Unicode literals escape notation), Beware of Encoding Defaults
- _ symbol, Pattern Matching with Sequences
- __ (double underscore), The Python Data Model
- __abs__, Emulating Numeric Types
- __add__, Emulating Numeric Types
- __bool__, Boolean Value of a Custom Type
- __bytes__, Object Representations
- __call__, Further Reading
- __class__, Special Attributes that Affect Attribute Handling, Classes as Objects
- __contains__, A Pythonic Card Deck, The __missing__ Method
- __delattr__, Special Methods for Attribute Handling
- __delete__, Attribute Descriptors
- __del__, del and Garbage Collection
- __dict__, Special Attributes that Affect Attribute Handling
- __dir__, Special Methods for Attribute Handling
- __enter__, Context Managers and with Blocks
- __eq__, Vector Take #4: Hashing and a Faster ==-Vector Take #4: Hashing and a Faster ==
- __exit__, Context Managers and with Blocks
- __format__, Object Representations, Formatted Displays, Vector Take #5: Formatting-Vector Take #5: Formatting, Further Reading
- __getattribute__, Special Methods for Attribute Handling
- __getattr__, Vector Take #3: Dynamic Attribute Access-Vector Take #3: Dynamic Attribute Access, Special Methods for Attribute Handling
- __getitem__, A Pythonic Card Deck-A Pythonic Card Deck, Multidimensional Slicing and Ellipsis, Vector Take #2: A Sliceable Sequence-A Slice-Aware __getitem__
- __get__, Attribute Descriptors
- __hash__, More About @dataclass, Vector Take #4: Hashing and a Faster ==-Vector Take #4: Hashing and a Faster ==
- __iadd__, Augmented Assignment with Sequences
- __init_subclass__, Introducing __init_subclass__-Why __init_subclass__ Cannot Configure __slots__
- __init__, How Special Methods Are Used, Post-init Processing, Vector Take #1: Vector2d Compatible
- __invert__, Unary Operators
- __iter__, Sentence Classes with __iter__-How a Generator Works
- __len__, A Pythonic Card Deck-A Pythonic Card Deck, Why len Is Not a Method, Vector Take #2: A Sliceable Sequence-A Slice-Aware __getitem__
- __missing__, The __missing__ Method-Inconsistent Usage of __missing__ in the Standard Library
- __mro__, Classes as Objects
- __mul__, Emulating Numeric Types
- __name__, Classes as Objects
- __neg__, Unary Operators
- __post_init__, Post-init Processing
- __pos__, Unary Operators
- __prepare__, A Metaclass Hack with __prepare__-A Metaclass Hack with __prepare__
- __repr__, Emulating Numeric Types-String Representation, Object Representations, Vector Take #1: Vector2d Compatible
- __setattr__, Special Methods for Attribute Handling
- __setitem__, Multidimensional Slicing and Ellipsis
- __set__, Attribute Descriptors
- __slots__, Saving Memory with __slots__-Summarizing the Issues with __slots__, Vector Take #3: Dynamic Attribute Access, Special Attributes that Affect Attribute Handling, Why __init_subclass__ Cannot Configure __slots__
- __str__, String Representation, Object Representations
- {} (curly brackets), List Comprehensions and Readability
- ǀ (pipe) operator, Merging Mappings with |, Using OR-patterns
- ǀ= (pipe equals) operator, Merging Mappings with |
- … (ellipsis), A Pythonic Card Deck, Multidimensional Slicing and Ellipsis
A
- abc.ABC class, ABCs in the Standard Library
- abc.Iterable, abc.Iterable versus abc.Sequence
- abc.Sequence, abc.Iterable versus abc.Sequence
- ABCs (abstract base classes)
- ABC syntax details, ABC Syntax Details
- defining and using ABCs, Defining and Using an ABC-Defining and Using an ABC
- further reading on, Further Reading
- goose typing and, Goose Typing-Goose Typing
- overview of, Chapter Summary
- in Python standard library, ABCs in the Standard Library-ABCs in the Standard Library
- Soapbox discussion, Further Reading-Further Reading
- structural typing with, Structural Typing with ABCs-Structural Typing with ABCs
- subclassing ABCs, Subclassing an ABC-Subclassing an ABC, Subclassing an ABC-Subclassing an ABC
- type hints (type annotations), Abstract Base Classes-The fall of the numeric tower
- UML class diagrams, Collection API-Collection API
- usage of register, Usage of register in Practice
- virtual subclasses of ABCs, A Virtual Subclass of an ABC-A Virtual Subclass of an ABC
- abs built-in function, Emulating Numeric Types
- actual type parameters, Basic Jargon for Generic Types
- addition assignment (+=) operator, Augmented Assignment with Sequences-A += Assignment Puzzler, Augmented Assignment Operators-Augmented Assignment Operators
- aliasing, Identity, Equality, and Aliases-The Relative Immutability of Tuples
- anonymous functions, Anonymous Functions, Further Reading, Closures
- Any type, The Any Type-Subtype-of versus consistent-with
- AnyStr, The AnyStr predefined type variable
- .append method, Deques and Other Queues
- apply function, Higher-Order Functions-Modern Replacements for map, filter, and reduce
- arguments
- arrays, Overview of Built-In Sequences, Arrays-Arrays
- as keyword, Pattern Matching with Sequences
- assignment expression (:=), List Comprehensions and Readability
- asynchronous generators, The Nine Flavors of Callable Objects, A Few Definitions
- asynchronous programming
- asynchronous context managers, Asynchronous Context Managers-Asynchronous Context Managers
- asyncio script example, An asyncio Example: Probing Domains-Guido’s Trick to Read Asynchronous Code
- avoiding CPU-bound traps, Avoiding CPU-Bound Traps
- awaitables, New Concept: Awaitable
- benefits of, Running Circles Around Blocking Calls
- Curio project, async Beyond asyncio: Curio-async Beyond asyncio: Curio
- delegating tasks to executors, Delegating Tasks to Executors-Delegating Tasks to Executors
- enhancing asyncio downloader, Enhancing the asyncio Downloader-Making Multiple Requests for Each Download
- further reading on, Further Reading
- iteration and iterables, Asynchronous Iteration and Asynchronous Iterables-Asynchronous comprehensions
- myth of I/O-bound systems, The Myth of I/O-Bound Systems
- overview of, Chapter Summary
- relevant terminology, A Few Definitions
- significant changes to, What’s New in This Chapter
- Soapbox discussion, Further Reading
- topics covered, Asynchronous Programming
- type hinting asynchronous objects, Type Hinting Asynchronous Objects
- writing asyncio servers, Writing asyncio Servers-An asyncio TCP Server
- Asynchronous Server Gateway Interface (ASGI), WSGI Application Servers
- asyncio package
- asyncpg, Asynchronous Context Managers
- attribute descriptors (see also attributes; dynamic attributes and properties)
- attribute validation, Descriptor Example: Attribute Validation-LineItem Take #5: A New Descriptor Type
- descriptor docstring and overriding deletion, Descriptor Docstring and Overriding Deletion
- descriptor usage tips, Descriptor Usage Tips-Descriptor Usage Tips
- further reading on, Further Reading
- methods as descriptors, Methods Are Descriptors-Methods Are Descriptors
- overriding versus nonoverriding, Step 5: Caching Properties with functools, Overriding Versus Nonoverriding Descriptors-Overwriting a Descriptor in the Class
- overview of, Chapter Summary
- purpose of, Attribute Descriptors
- relevant terminology, Terms to understand descriptors
- significant changes to, What’s New in This Chapter
- Soapbox discussion, Further Reading
- topics covered, Attribute Descriptors
- attributes (see also attribute descriptors; dynamic attributes and properties)
- augmented assignment operators, Augmented Assignment with Sequences-A += Assignment Puzzler, Augmented Assignment Operators-Augmented Assignment Operators
- averages, computing, Example: Coroutine to Compute a Running Average-Example: Coroutine to Compute a Running Average
- await keyword, New Concept: Awaitable
B
- backslash (\), List Comprehensions and Readability
- behavioral subtyping, Subtype-of versus consistent-with
- binary records, parsing with struct, What’s New in This Chapter
- binary sequences, Byte Essentials (see also Unicode text versus bytes)
- bisect module, list.sort Versus the sorted Built-In
- blue tool, A Default Parameter Value
- BOMs (byte-order marks), BOM: A Useful Gremlin
- bool type, Boolean Value of a Custom Type
- Boolean values, custom types and, Boolean Value of a Custom Type
- built-in functions, The Nine Flavors of Callable Objects
- byte sequences, How to Discover the Encoding of a Byte Sequence (see also Unicode text versus bytes)
- bytecode, disassembling, Variable Scope Rules
C
- call by sharing, Function Parameters as References
- callable objects
- Callable type, Callable
- card deck example, A Pythonic Card Deck-A Pythonic Card Deck
- Cartesian products, Cartesian Products-Cartesian Products
- case folding, Case Folding
- chain generator, Reinventing chain
- ChainMap, collections.ChainMap
- characters
- Chardet library, How to Discover the Encoding of a Byte Sequence
- cladistics, Goose Typing
- class metaprogramming
- benefits and drawbacks of, Class Metaprogramming
- built-in class factory, type: The Built-In Class Factory
- class factory function, A Class Factory Function-A Class Factory Function
- classes as objects, Classes as Objects
- enhancing classes with class decorators, Enhancing Classes with a Class Decorator-Enhancing Classes with a Class Decorator
- further reading on, Further Reading
- import time versus runtime, What Happens When: Import Time Versus Runtime-Evaluation Time Experiments
- __init_subclass__, Introducing __init_subclass__-Why __init_subclass__ Cannot Configure __slots__
- metaclass basics, Metaclasses 101-Metaclass Evaluation Time Experiment
- metaclass issues, Metaclasses in the Real World-Metaclasses Should Be Implementation Details
- metaclass solution for checkedlib.py, A Metaclass Solution for Checked-A Metaclass Solution for Checked
- overview of, Chapter Summary
- __prepare__ method, A Metaclass Hack with __prepare__-A Metaclass Hack with __prepare__
- significant changes to, What’s New in This Chapter
- Soapbox discussion, Further Reading
- useful applications of metaclasses, Wrapping Up
- classes (see also protocols)
- classic refactoring strategy, Classic Strategy-Classic Strategy
- classmethod decorator, classmethod Versus staticmethod
- client codes, Subgenerators with yield from
- clock decorators
- closures (see decorators and closures)
- cls.mro(), Classes as Objects
- cls.__bases__, Classes as Objects
- cls.__qualname__, Classes as Objects
- cls.__subclasses__(), Classes as Objects
- code examples, obtaining and using, Using Code Examples
- code points, Character Issues, Further Reading
- code smells, Data Class Builders, Data Class as a Code Smell-Data Class as Intermediate Representation, Goose Typing
- codecs, Basic Encoders/Decoders
- Collection API, Collection API-Collection API
- collections.abc module
- collections.deque class, Deques and Other Queues-Deques and Other Queues
- collections.namedtuple, A Pythonic Card Deck, Classic Named Tuples-Classic Named Tuples
- Command pattern, The Command Pattern-The Command Pattern
- comments and questions, How to Contact Us
- comparison operators, Identity, Equality, and Aliases, Rich Comparison Operators-Rich Comparison Operators
- computed properties
- concatenation, Using + and * with Sequences-A += Assignment Puzzler
- concurrency models
- basics of concurrency, The Big Picture
- benefits of concurrency, Concurrency Models in Python
- further reading on, Further Reading-Concurrency and Scalability Beyond Python
- Global Interpreter Lock impact, The Real Impact of the GIL-3. Answer for asyncio
- Hello World example, A Concurrent Hello World-Supervisors Side-by-Side
- indefinite loops and sentinels, Code for the Multicore Prime Checker
- multicore processors and, Python in the Multicore World-Distributed Task Queues
- overview of, Chapter Summary
- process pools, A Homegrown Process Pool-Thread-Based Nonsolution
- Python programming concepts, Processes, Threads, and Python’s Infamous GIL-Processes, Threads, and Python’s Infamous GIL
- relevant terminology, A Bit of Jargon-A Bit of Jargon
- significant changes to, What’s New in This Chapter
- Soapbox discussion, Concurrency and Scalability Beyond Python-Concurrency and Scalability Beyond Python
- structured concurrency, async Beyond asyncio: Curio
- topics covered, Concurrency Models in Python
- concurrent executors
- concurrent.futures
- consistent-with relationships, Subtype-of versus consistent-with
- Container interface, Collection API
- container sequences, Overview of Built-In Sequences, Further Reading
- contention, A Bit of Jargon
- context managers
- contravariance (see variance)
- control flow, How the Book Is Organized (see also asynchronous programming; concurrent executors; concurrency models; iterators; generators; with, match, and else blocks)
- cooperative multiple inheritance, Multiple Inheritance and Method Resolution Order
- copies
- coroutine objects, Classic Coroutines
- coroutines
- computing running averages, Example: Coroutine to Compute a Running Average-Example: Coroutine to Compute a Running Average
- definition of term, A Bit of Jargon
- further reading on, Further Reading
- generator-based, A Few Definitions
- generic type hints for, Generic Type Hints for Classic Coroutines
- Global Interpreter Lock impact, 3. Answer for asyncio
- overview of, Chapter Summary
- returning values from, Returning a Value from a Coroutine-Returning a Value from a Coroutine
- significant changes to, What’s New in This Chapter
- Soapbox discussion, Further Reading
- spinners (loading indicators) using, Spinner with Coroutines-Experiment: Break the spinner for an insight
- topics covered, Iterators, Generators,
and Classic Coroutines
- types of, A Few Definitions
- understanding classic, Classic Coroutines
- Counter, collections.Counter
- covariance (see variance)
- CPU-bound systems, Avoiding CPU-Bound Traps
- Curio project, async Beyond asyncio: Curio-async Beyond asyncio: Curio
- curly brackets ({}), List Comprehensions and Readability
D
- Dask, Data Science
- data attributes (see attributes)
- data class builders
- @dataclass, More About @dataclass-@dataclass Example: Dublin Core Resource Record
- classic named tuples, Classic Named Tuples-Classic Named Tuples
- data class as code smell, Data Class as a Code Smell-Data Class as Intermediate Representation
- further reading on, Further Reading
- main features, Main Features-New class at runtime
- overview of, Overview of Data Class Builders-Overview of Data Class Builders, Chapter Summary
- pattern matching class instances, Pattern Matching Class Instances-Positional Class Patterns
- significant changes to, What’s New in This Chapter
- Soapbox discussion, Further Reading
- topics covered, Data Class Builders
- type hints, Type Hints 101-Inspecting a class decorated with dataclass
- typed named tuples, Typed Named Tuples
- data descriptors (see overriding descriptors)
- data model (see Python Data Model)
- data science, Data Science
- data structures, How the Book Is Organized (see also data class builders; dictionaries and sets; object references; sequences; Unicode text versus bytes)
- data wrangling
- decimal.Decimal class, Unary Operators
- decoding (see also Unicode text versus bytes)
- decorator-enhanced strategy pattern, Decorator-Enhanced Strategy Pattern-Decorator-Enhanced Strategy Pattern
- decorators and closures
- classmethod versus staticmethod, classmethod Versus staticmethod
- closure basics, Closures-Closures
- closures in lis.py, Procedure: A Class Implementing a Closure
- decorator basics, Decorators 101-Decorators 101
- decorator execution, When Python Executes Decorators
- decorator implementation, Implementing a Simple Decorator-How It Works
- decorators in Python standard library, Decorators in the Standard Library-Memoization with functools.cache
- enhancing classes with class decorators, Enhancing Classes with a Class Decorator-Enhancing Classes with a Class Decorator
- further reading on, Further Reading
- nonlocal declarations, The nonlocal Declaration-Variable Lookup Logic
- overview of, Chapter Summary
- parameterized decorators, Parameterized Decorators-A Class-Based Clock Decorator
- purpose of, Decorators and Closures
- registration decorators, Registration Decorators
- significant changes to, What’s New in This Chapter
- Soapbox discussion, Further Reading-Further Reading
- topics covered, Decorators and Closures
- variable scope rules, Variable Scope Rules-Variable Scope Rules
- deep copies, Deep and Shallow Copies of Arbitrary Objects-Deep and Shallow Copies of Arbitrary Objects
- defaultdict, Overview of Common Mapping Methods, defaultdict: Another Take on Missing Keys
- defensive programming, Inserting or Updating Mutable Values, Defensive Programming and “Fail Fast”-Defensive Programming and “Fail Fast”
- del statement, del and Garbage Collection-del and Garbage Collection, Handling Attribute Deletion
- delegating generators, Subgenerators with yield from
- deprecated collection types, Generic Collections
- deque (double-ended queue), When a List Is Not the Answer, Deques and Other Queues-Deques and Other Queues
- descriptor classes, Terms to understand descriptors
- descriptor instances, Terms to understand descriptors
- descriptors, Inspecting a typing.NamedTuple, Attribute Descriptors (see also attribute descriptors)
- design patterns (see functions, design patterns with first-class)
- destructuring, Pattern Matching with Sequences
- diacritics, normalization and, Extreme “Normalization”: Taking Out Diacritics-Extreme “Normalization”: Taking Out Diacritics
- dictcomps (dict comprehensions), dict Comprehensions
- dictionaries and sets
- automatic handling of missing keys, Automatic Handling of Missing Keys-Inconsistent Usage of __missing__ in the Standard Library
- consequences of how dict works, Practical Consequences of How dict Works
- consequences of how set works, Practical Consequences of How Sets Work
- dictionary views, Dictionary Views-Dictionary Views
- further reading on, Further Reading
- immutable mappings, Immutable Mappings
- internals of, What’s New in This Chapter
- modern dict syntax, Modern dict Syntax-Merging Mappings with |
- overview of, Chapter Summary
- pattern matching with mappings, Pattern Matching with Mappings-Pattern Matching with Mappings
- set operations, Set Operations-Set Operations
- set operations on dict views, Set Operations on dict Views
- set theory, Set Theory-Set Comprehensions
- significant changes to, What’s New in This Chapter
- Soapbox discussion, Further Reading
- standard API of mapping types, Standard API of Mapping Types-Inserting or Updating Mutable Values
- topics covered, Dictionaries and Sets
- variations of dict, Variations of dict-Subclassing UserDict Instead of dict
- dir([object]) function, Built-In Functions for Attribute Handling
- dis module, Variable Scope Rules
- displays, formatting, Formatted Displays-Formatted Displays
- distributed task queues, Distributed Task Queues
- Django generic views mixins, Django Generic Views Mixins-Django Generic Views Mixins
- doctest package
- double star (**) operator, Unpacking Mappings, From Positional to Keyword-Only Parameters
- double underscore (__), The Python Data Model
- double() function, The Typed double Function-The Typed double Function
- Dublin Core Schema, @dataclass Example: Dublin Core Resource Record
- duck typing, Overview of Common Mapping Methods, Types Are Defined by Supported Operations, Further Reading, Protocols and Duck Typing, Further Reading, Interfaces, Protocols, and ABCs, Runtime Checkable Static Protocols
- dunder methods, The Python Data Model
- dynamic attributes and properties
- coding property factories, Coding a Property Factory-Coding a Property Factory
- computed properties, Computed Properties-Step 5: Caching Properties with functools
- data wrangling with dynamic attributes, Data Wrangling with Dynamic Attributes-Flexible Object Creation with __new__
- dynamic versus virtual attributes, Dynamic Attributes and Properties
- essential attributes and functions for attribute handling, Essential Attributes and Functions for Attribute Handling-Special Methods for Attribute Handling
- further reading on, Further Reading
- handling attribute deletion, Handling Attribute Deletion
- overview of, Chapter Summary
- property class, A Proper Look at Properties-Property Documentation
- significant changes to, What’s New in This Chapter
- Soapbox discussion, Further Reading-Further Reading
- using properties for attribute validation, Using a Property for Attribute Validation-LineItem Take #2: A Validating Property
- dynamic protocols, Protocols and Duck Typing, Two Kinds of Protocols
- dynamic type, The Any Type-Subtype-of versus consistent-with
E
- ellipsis (…), A Pythonic Card Deck, Multidimensional Slicing and Ellipsis
- else blocks, Do This, Then That: else Blocks Beyond if-Do This, Then That: else Blocks Beyond if
- emojis
- encoding (see also Unicode text versus bytes)
- equality (==) operator, Identity, Equality, and Aliases, Further Reading, Rich Comparison Operators
- error handling, in network I/O, Downloads with Progress Display and Error Handling-Using futures.as_completed
- execution units, A Bit of Jargon
- Executor.map, Experimenting with Executor.map-Experimenting with Executor.map
- executors, delegating tasks to, Delegating Tasks to Executors-Delegating Tasks to Executors (see also concurrent executors)
- explicit self argument, Further Reading
F
- f-string syntax
- fail-fast philosophy, Inserting or Updating Mutable Values, Vector Take #4: Hashing and a Faster ==, Defensive Programming and “Fail Fast”-Defensive Programming and “Fail Fast”
- FastAPI framework, A FastAPI Web Service-A FastAPI Web Service
- FIFO (first in, first out), When a List Is Not the Answer, Deques and Other Queues
- filter function, Listcomps Versus map and filter, Higher-Order Functions-Modern Replacements for map, filter, and reduce
- filtering generator functions, Generator Functions in the Standard Library
- first-class functions (see functions, as first-class objects)
- first-class objects, Functions as First-Class Objects
- flake8 tool, A Default Parameter Value
- flat sequences, Overview of Built-In Sequences, Further Reading
- flawed typing, Imperfect Typing and Strong Testing
- fluentpython.com, Companion Website: fluentpython.com
- ForkingMixIn, ThreadingMixIn and ForkingMixIn
- formal type parameters, Basic Jargon for Generic Types
- format() function, Formatted Displays
- forward reference problem, Problems with Annotations at Runtime
- free variables, Closures, Procedure: A Class Implementing a Closure
- frozenset, Set Theory (see also dictionaries and sets)
- function decorators (see decorators and closures)
- function parameters, introspection of, What’s New in This Chapter
- function-class duality, Further Reading
- function-oriented refactoring strategy, Function-Oriented Strategy-Function-Oriented Strategy
- functional programming
- functions
- abs built-in function, Emulating Numeric Types
- dir([object]) function, Built-In Functions for Attribute Handling
- disassembling bytecode of, Variable Scope Rules
- double() function, The Typed double Function
- filter, map, and reduce functions, Listcomps Versus map and filter, Higher-Order Functions
- format() function, Formatted Displays
- getattr function, Special Methods for Attribute Handling
- getattr(object, name[, default]) function, Built-In Functions for Attribute Handling
- globals() function, Finding Strategies in a Module
- hasattr function, Special Methods for Attribute Handling
- higher-order functions, Higher-Order Functions-Modern Replacements for map, filter, and reduce
- id() function, Identity, Equality, and Aliases
- iter() function, Why Sequences Are Iterable: The iter Function
- len() function, A Pythonic Card Deck
- map function, Listcomps Versus map and filter
- max() function, Max Overload
- repr() function, Object Representations
- setattr funcion, Special Methods for Attribute Handling
- setattr(object, name, value) function, Built-In Functions for Attribute Handling, Built-In Functions for Attribute Handling
- single dispatch generic functions, Single Dispatch Generic Functions-Function singledispatch
- str() function, String Representation, Object Representations
- super() function, Vector Take #3: Dynamic Attribute Access, The super() Function
- zip() function, Vector Take #4: Hashing and a Faster ==
- functions, as first-class objects (see also decorators and closures)
- anonymous functions, Anonymous Functions
- callable objects, The Nine Flavors of Callable Objects-The Nine Flavors of Callable Objects
- definition of term, Functions as First-Class Objects
- flexible parameter handling and, From Positional to Keyword-Only Parameters-Positional-Only Parameters
- further reading on, Further Reading
- higher-order functions, Higher-Order Functions-Modern Replacements for map, filter, and reduce
- overview of, Chapter Summary
- packages for functional programming, Packages for Functional Programming-Freezing Arguments with functools.partial
- significant changes to, What’s New in This Chapter
- Soapbox discussion, Further Reading
- topics covered, How the Book Is Organized
- treating functions like objects, Treating a Function Like an Object-Treating a Function Like an Object
- user-defined callable types, User-Defined Callable Types
- functions, design patterns with first-class
- functions, type hints in
- annotating positional only and variadic parameters, Annotating Positional Only and Variadic Parameters
- benefits and drawbacks of, Type Hints in Functions
- flawed typing and strong testing, Imperfect Typing and Strong Testing
- further reading on, Further Reading
- gradual typing, About Gradual Typing-Using None as a Default
- overview of, Chapter Summary
- significant changes to, What’s New in This Chapter
- Soapbox discussion, Further Reading-Further Reading
- supported operations and, Types Are Defined by Supported Operations-Types Are Defined by Supported Operations
- topics covered, Type Hints in Functions
- types usable in annotations, Types Usable in Annotations-NoReturn
- functools module
- futures
- futures.as_completed, Using futures.as_completed-Using futures.as_completed
G
- garbage collection, del and Garbage Collection-del and Garbage Collection, Further Reading
- generator expressions (genexps), List Comprehensions and Readability, Generator Expressions, Modern Replacements for map, filter, and reduce, When to Use Generator Expressions, Async Comprehensions and Async Generator Expressions-Asynchronous comprehensions
- generators
- arithmetic progression generators, An Arithmetic Progression Generator-Arithmetic Progression with itertools
- asynchronous generator functions, Asynchronous Generator Functions-Asynchronous generators versus native coroutines
- examples of, How a Generator Works-How a Generator Works
- further reading on, Further Reading
- generator functions in Python standard library, The Nine Flavors of Callable Objects, Generator Functions in the Standard Library-Generator Functions in the Standard Library
- generator-based coroutines, A Few Definitions
- generic iterable types, Generic Iterable Types
- humble generators, The Secret of Native Coroutines: Humble Generators
- iterable reducing functions, Iterable Reducing Functions-Iterable Reducing Functions
- versus iterators, When to Use Generator Expressions
- lazy generators, Lazy Sentences-Sentence Take #5: Lazy Generator Expression
- overview of, Chapter Summary
- Sentence classes with, Sentence Take #3: A Generator Function
- significant changes to, What’s New in This Chapter
- Soapbox discussion, Further Reading
- subgenerators with yield from expression, Subgenerators with yield from-Traversing a Tree
- topics covered, Iterators, Generators,
and Classic Coroutines
- when to use generator expressions, When to Use Generator Expressions
- yield keyword, How a Generator Works
- generic classes, implementing, Implementing a Generic Class-Basic Jargon for Generic Types
- generic collections
- generic functions, single dispatch, Single Dispatch Generic Functions-Function singledispatch
- generic mapping types, Generic Mappings
- generic static protocols, Implementing a Generic Static Protocol-Implementing a Generic Static Protocol
- getattr function, Special Methods for Attribute Handling
- getattr(object, name[, default]) function, Built-In Functions for Attribute Handling
- gevent library, Experiment: Break the spinner for an insight
- Global Interpreter Lock (GIL), NumPy, Processes, Threads, and Python’s Infamous GIL, The Real Impact of the GIL-3. Answer for asyncio, Python in the Multicore World, The GIL
- globals() function, Finding Strategies in a Module
- goose typing
- ABC syntax details, ABC Syntax Details
- ABCs in Python standard library, ABCs in the Standard Library-ABCs in the Standard Library
- abstract base classes (ABCs), Goose Typing-Goose Typing
- defining and using ABCs, Defining and Using an ABC-Defining and Using an ABC
- definition of term, Interfaces, Protocols, and ABCs
- overview of, Goose Typing
- structural typing with ABCs, Structural Typing with ABCs-Structural Typing with ABCs
- subclassing ABCs, Subclassing an ABC-Subclassing an ABC, Subclassing an ABC-Subclassing an ABC
- usage of register, Usage of register in Practice
- virtual subclasses of ABCs, A Virtual Subclass of an ABC-A Virtual Subclass of an ABC
- gradual type system (see also type hints (type annotations))
- abstract base classes, Abstract Base Classes-The fall of the numeric tower
- Any type, The Any Type-The Any Type
- basics of, About Gradual Typing
- Callable type, Callable
- further reading on, Further Reading
- generic collections, Generic Collections-Generic Collections
- generic mappings, Generic Mappings
- implementing generic classes, Implementing a Generic Class-Basic Jargon for Generic Types
- implementing generic static protocols, Implementing a Generic Static Protocol-Implementing a Generic Static Protocol
- in practice, Gradual Typing in Practice-Using None as a Default
- Iterable, Iterable-abc.Iterable versus abc.Sequence
- legacy support and deprecated collection types, Generic Collections
- NoReturn type, NoReturn
- Optional and Union types, Optional and Union Types
- overloaded signatures, Overloaded Signatures-Takeaways from Overloading max
- overview of, Chapter Summary
- parameterized generics and TypeVar, Parameterized Generics and TypeVar-The AnyStr predefined type variable
- reading hints at runtime, Reading Type Hints at Runtime-Dealing with the Problem
- significant changes to, What’s New in This Chapter
- simple types and classes, Simple Types and Classes
- Soapbox discussion, Further Reading
- static protocols, Static Protocols-Static Protocols
- subtype-of versus consistent-with relationships, Subtype-of versus consistent-with-Subtype-of versus consistent-with
- topics covered, More About Type Hints
- tuple types, Tuple Types-Tuples as immutable sequences
- type casting, Type Casting-Type Casting
- TypedDict, TypedDict
- variance and, Variance-Variance rules of thumb
- greater than (>) operator, Rich Comparison Operators
- greater than or equal to (>=) operator, Rich Comparison Operators
- greenlet package, Experiment: Break the spinner for an insight
H
- hasattr function, Special Methods for Attribute Handling
- hash code, versus hash value, What Is Hashable
- hash tables, Dictionaries and Sets
- hashable, definition of, What Is Hashable
- heapq package, Deques and Other Queues
- higher-order functions, Higher-Order Functions-Modern Replacements for map, filter, and reduce
- HTTPServer class, ThreadingMixIn and ForkingMixIn
- HTTPX library, Downloading with asyncio and HTTPX-The All-or-Nothing Problem
- humble generators, The Secret of Native Coroutines: Humble Generators
I
- I/O (input/output) (see network I/O)
- id() function, Identity, Equality, and Aliases
- immutable mappings, Immutable Mappings
- immutable sequences, Overview of Built-In Sequences
- implicit conversion, Unicode Text Versus Bytes
- import time versus runtime, When Python Executes Decorators, What Happens When: Import Time Versus Runtime
- indefinite loops, Code for the Multicore Prime Checker
- infix operators, Operator Overloading, Using @ as an Infix Operator-Wrapping-Up Arithmetic Operators
- inheritance and subclassing
- best practices, Coping with Inheritance-Tkinter: The Good, the Bad, and the Ugly
- further reading on, Further Reading
- mixin classes, Mixin Classes-Case-Insensitive Mappings
- multiple inheritance and method resolution order, Multiple Inheritance and Method Resolution Order-Multiple Inheritance and Method Resolution Order
- overview of, Chapter Summary
- real-world examples of, Multiple Inheritance in the Real World-Multiple Inheritance in Tkinter
- significant changes to, What’s New in This Chapter
- Soapbox discussion, Further Reading-Further Reading
- subclassing ABCs, Subclassing an ABC-Subclassing an ABC, Subclassing an ABC-Subclassing an ABC
- subclassing built-in types, Subclassing Built-In Types Is Tricky-Subclassing Built-In Types Is Tricky
- super() function, The super() Function-The super() Function
- topics covered, Inheritance: For Better or for Worse
- virtual subclasses of ABCs, A Virtual Subclass of an ABC-A Virtual Subclass of an ABC
- input expanding generator functions, Generator Functions in the Standard Library
- interfaces (see also goose typing; protocols)
- Container interface, Collection API
- further reading on, Further Reading
- Iterable interface, Collection API, Iterable, Programming Ducks
- overview of, Chapter Summary
- protocols as informal, Further Reading
- role in object-oriented programming, Interfaces, Protocols, and ABCs
- significant changes to, What’s New in This Chapter
- Sized interface, Collection API
- Soapbox discussion, Further Reading-Further Reading
- topics covered, The Typing Map
- typing map, The Typing Map
- ways of defining and using, Interfaces, Protocols, and ABCs
- interning, Tricks Python Plays with Immutables
- invalid attribute name problem, The Invalid Attribute Name Problem
- inverted indexes, Writing asyncio Servers
- is operator, Choosing Between == and is, Tricks Python Plays with Immutables
- .items method, Set Operations on dict Views
- iter() function, Why Sequences Are Iterable: The iter Function-Using iter with a Callable
- Iterable interface, Collection API, Iterable-abc.Iterable versus abc.Sequence, Programming Ducks-Python Digs Sequences
- iterables
- iterators
- asynchronous, Asynchronous Iteration and Asynchronous Iterables-Asynchronous comprehensions
- further reading on, Further Reading
- versus generators, When to Use Generator Expressions
- generic iterable types, Generic Iterable Types
- iter() function, Why Sequences Are Iterable: The iter Function-Using iter with a Callable
- versus iterables, Iterables Versus Iterators-Iterables Versus Iterators
- lazy sentences, Lazy Sentences-Sentence Take #5: Lazy Generator Expression
- overview of, Chapter Summary
- role of, Iterators, Generators,
and Classic Coroutines
- Sentence classes with __iter__, Sentence Classes with __iter__-How a Generator Works
- sequence protocol, A Sequence of Words-A Sequence of Words
- significant changes to, What’s New in This Chapter
- Soapbox discussion, Further Reading
- topics covered, Iterators, Generators,
and Classic Coroutines
- itertools module, Arithmetic Progression with itertools
K
- key argument, Further Reading
- keys
- .keys method, Set Operations on dict Views
- keyword class patterns, Keyword Class Patterns
- keyword-only arguments, From Positional to Keyword-Only Parameters
- keywords
- as keyword, Pattern Matching with Sequences
- await keyword, New Concept: Awaitable
- lambda keyword, Anonymous Functions
- nonlocal keyword, The nonlocal Declaration-Variable Lookup Logic, (set! …)
- reserved keywords, (quote …)
- yield keyword, The Nine Flavors of Callable Objects, Don’t Make the Iterable an Iterator for Itself-How a Generator Works, When to Use Generator Expressions, Classic Coroutines, Example: Coroutine to Compute a Running Average, Using @contextmanager
- KISS principle, Further Reading, Further Reading, Concurrency and Scalability Beyond Python
L
- lambda keyword, Anonymous Functions
- lazy sentences, Lazy Sentences-Sentence Take #5: Lazy Generator Expression
- Least Recently Used (LRU), Using lru_cache
- len() function, A Pythonic Card Deck
- less than (<) operator, Rich Comparison Operators
- less than or equal to (<=) operator, Rich Comparison Operators
- line breaks, List Comprehensions and Readability
- lis.py interpreter
- Environment class, The Environment
- evaluate function, The Evaluator-Catch syntax errors
- imports and types, Imports and Types
- OR-patterns, Using OR-patterns
- parser, The Parser-The Parser
- pattern matching in, Pattern Matching Sequences in an Interpreter-Shortcut syntax for function definition
- Procedure class, Procedure: A Class Implementing a Closure-Procedure: A Class Implementing a Closure
- REPL (read-eval-print-loop), The REPL
- Scheme syntax, Scheme Syntax-Scheme Syntax
- topics covered, Pattern Matching in lis.py: A Case Study
- list comprehensions (listcomps)
- asynchronous, Async Comprehensions and Async Generator Expressions-Asynchronous comprehensions
- building lists from cartesian products, Cartesian Products
- building sequences with, List Comprehensions and Generator Expressions
- versus generator expressions, Generator Expressions
- local scope within, List Comprehensions and Readability
- readability and, List Comprehensions and Readability
- syntax tip, List Comprehensions and Readability
- versus map and filter functions, Listcomps Versus map and filter, Modern Replacements for map, filter, and reduce
- lists
- locks, definition of term, A Bit of Jargon
- LRU (see Least Recently Used)
M
- magic methods, The Python Data Model, Further Reading
- managed attributes, Terms to understand descriptors
- managed classes, Terms to understand descriptors
- managed instances, Terms to understand descriptors
- map function, Listcomps Versus map and filter, Higher-Order Functions-Modern Replacements for map, filter, and reduce
- mappings
- match blocks (see with, match, and else blocks)
- match/case statement, Pattern Matching with Sequences, Pattern Matching with Mappings
- mathematical vector operations, Overloading + for Vector Addition
- max() function, Max Overload-Takeaways from Overloading max
- memoization, Memoization with functools.cache-Memoization with functools.cache
- memory, saving with __slots__, Saving Memory with __slots__-Summarizing the Issues with __slots__
- memoryview class, Memory Views-Memory Views
- metaclasses
- metaobjects, Further Reading
- metaprogramming, How the Book Is Organized (see also attribute descriptors; class metaprogramming; dynamic attributes and properties)
- method resolution order (MRO), Multiple Inheritance and Method Resolution Order-Multiple Inheritance and Method Resolution Order
- methods, as callable objects, The Nine Flavors of Callable Objects (see also sequences, special methods for; special methods)
- Meyer's Uniform Access Principle, Further Reading-Further Reading
- Mills & Gizmos Notation (MGN), Terms to understand descriptors
- mixin classes, Mixin Classes-Case-Insensitive Mappings
- mixin methods, ABCs Are Mixins Too
- modulo (%) operator, What’s New in This Chapter, String Representation
- monkey-patching, Monkey Patching: Implementing a Protocol at Runtime-Monkey Patching: Implementing a Protocol at Runtime, Further Reading, Overwriting a Descriptor in the Class
- MRO (see method resolution order)
- multicore processing
- multiline lists, List Comprehensions and Readability
- multiple inheritance (see also inheritance and subclassing)
- multiplication, scalar, Emulating Numeric Types, Overloading * for Scalar Multiplication-Overloading * for Scalar Multiplication
- multiprocessing package, Deques and Other Queues, Spinner with Processes
- mutable objects, Further Reading (see also object references)
- mutable parameters, Mutable Types as Parameter Defaults: Bad Idea-Defensive Programming with Mutable Parameters
- mutable sequences, Overview of Built-In Sequences
- mutable values, inserting or updating, Inserting or Updating Mutable Values-Inserting or Updating Mutable Values
- MutableMapping ABC, Standard API of Mapping Types
- Mypy type checker, Gradual Typing in Practice-Using None as a Default
- my_fmt.format() method, What’s New in This Chapter
N
- name mangling, Private and “Protected” Attributes in Python
- namedtuple, Classic Named Tuples-Classic Named Tuples
- native coroutines
- network I/O
- NFC (see Normalization Form C)
- nominal typing, Types Are Defined by Supported Operations
- nonlocal keyword, The nonlocal Declaration-Variable Lookup Logic, (set! …)
- nonoverriding descriptors, Step 5: Caching Properties with functools, Overriding Versus Nonoverriding Descriptors-Overwriting a Descriptor in the Class
- NoReturn type, NoReturn
- Normalization Form C (NFC), Normalizing Unicode for Reliable Comparisons
- normalized text matching, Utility Functions for Normalized Text Matching-Extreme “Normalization”: Taking Out Diacritics
- not equal to (!=) operator, Rich Comparison Operators
- numbers ABCs, The numbers ABCs and Numeric Protocols-The numbers ABCs and Numeric Protocols
- numbers package, The fall of the numeric tower
- numeric protocols, The numbers ABCs and Numeric Protocols-The numbers ABCs and Numeric Protocols
- numeric tower, The fall of the numeric tower
- numeric types
- NumPy, NumPy-NumPy
O
- object references
- aliasing, Identity, Equality, and Aliases-The Relative Immutability of Tuples
- deep copies, Deep and Shallow Copies of Arbitrary Objects-Deep and Shallow Copies of Arbitrary Objects
- del and garbage collection, del and Garbage Collection-del and Garbage Collection
- distinction between objects and their names, Object References, Mutability, and Recycling
- function parameters as references, Function Parameters as References-Defensive Programming with Mutable Parameters
- further reading on, Further Reading
- immutability and, Tricks Python Plays with Immutables
- overview of, Chapter Summary
- shallow copies, Copies Are Shallow by Default-Copies Are Shallow by Default
- Soapbox discussion, Further Reading
- variables as labels versus boxes, Variables Are Not Boxes-Variables Are Not Boxes
- objects
- operator module, The operator Module-The operator Module
- operator overloading
- augmented assignment operators, Augmented Assignment Operators-Augmented Assignment Operators
- basics of, Operator Overloading 101
- further reading on, Further Reading
- infix operator method names, Wrapping-Up Arithmetic Operators
- infix operators, Operator Overloading
- overloading * for scalar multiplication, Overloading * for Scalar Multiplication-Overloading * for Scalar Multiplication
- overloading + for vector addition, Overloading + for Vector Addition-Overloading + for Vector Addition
- overview of, Chapter Summary
- rich comparison operators, Rich Comparison Operators-Rich Comparison Operators
- significant changes to, What’s New in This Chapter
- Soapbox discussion, Further Reading
- topics covered, Operator Overloading
- unary operators, Unary Operators-Unary Operators
- using @ as infix operator, Using @ as an Infix Operator-Using @ as an Infix Operator
- Optional type, Optional and Union Types
- OR-patterns, Using OR-patterns
- OrderedDict, Overview of Common Mapping Methods, collections.OrderedDict
- os functions, str versus bytes in, str Versus bytes in os Functions
- overloaded signatures, Overloaded Signatures-Takeaways from Overloading max
- overriding descriptors, Step 5: Caching Properties with functools, Properties Override Instance Attributes, Overriding Versus Nonoverriding Descriptors-Overwriting a Descriptor in the Class
P
- parallelism, Concurrency Models in Python, A Bit of Jargon
- parameterized decorators, Parameterized Decorators-A Class-Based Clock Decorator
- parameterized types, Basic Jargon for Generic Types
- parameters
- pattern matching
- *_ symbol, Pattern Matching with Sequences
- destructuring, Pattern Matching with Sequences
- in lis.py interpreter, Pattern Matching Sequences in an Interpreter-Shortcut syntax for function definition, Pattern Matching in lis.py: A Case Study-Using OR-patterns
- with mappings, Pattern Matching with Mappings-Pattern Matching with Mappings
- match/case statement, Pattern Matching with Sequences
- pattern matching class instances, Pattern Matching Class Instances-Positional Class Patterns
- tuples and lists, Pattern Matching with Sequences
- type information, Pattern Matching with Sequences
- _ symbol, Pattern Matching with Sequences
- patterns (see functions, design patterns with first-class; pattern matching)
- pickle module, shelve.Shelf
- Pingo library, Immutable Mappings
- pipe (ǀ) operator, Merging Mappings with |, Using OR-patterns
- pipe equals (ǀ=) operator, Merging Mappings with |
- plain text, How to Discover the Encoding of a Byte Sequence, Further Reading
- .pop method, Deques and Other Queues
- positional class patterns, Positional Class Patterns
- positional parameters, From Positional to Keyword-Only Parameters-Positional-Only Parameters
- positional patterns, Supporting Positional Pattern Matching
- process pools
- processes
- progress displays, Downloads with Progress Display and Error Handling-Using futures.as_completed
- Project Jupyter, Data Science
- proper tail calls (PTC), Further Reading-Further Reading
- properties (see computed properties; dynamic attributes and properties)
- property class, A Proper Look at Properties-Property Documentation
- protocol classes, Protocols and Duck Typing
- Protocol type, Static Protocols-Static Protocols
- protocols (see also interfaces)
- defensive programming, Defensive Programming and “Fail Fast”-Defensive Programming and “Fail Fast”
- duck typing and, Protocols and Duck Typing
- further reading on, Further Reading
- implementing at runtime, Monkey Patching: Implementing a Protocol at Runtime-Monkey Patching: Implementing a Protocol at Runtime
- implementing generic static protocols, Implementing a Generic Static Protocol-Implementing a Generic Static Protocol
- as informal interfaces, Further Reading
- meanings of protocol, Two Kinds of Protocols
- numeric, The numbers ABCs and Numeric Protocols-The numbers ABCs and Numeric Protocols
- overview of, Chapter Summary
- sequence and iterable protocols, Programming Ducks-Python Digs Sequences
- significant changes to, What’s New in This Chapter
- Soapbox discussion, Further Reading-Further Reading
- static protocols, Protocols and Duck Typing, Static Protocols-The numbers ABCs and Numeric Protocols
- topics covered, The Typing Map
- PSF (see Python Software Foundation)
- PUG (see Python Users Group)
- PyICU, Sorting with the Unicode Collation Algorithm
- PyLadies, Afterword
- pytest package, Hands-On Approach
- Python
- appreciating language-specific features, Preface
- approach to learning, Five Books in One-Hands-On Approach
- community support for, Afterword
- fluentpython.com, Companion Website: fluentpython.com
- functional programming with, Further Reading
- functioning with multicore processors, Python in the Multicore World-Distributed Task Queues
- further reading on, Further Reading
- prerequisites to learning, Who This Book Is For
- target audience, Who This Book Is Not For
- versions featured, Who This Book Is For
- Python Data Model
- Python Software Foundation (PSF), Afterword
- Python type checkers, Gradual Typing in Practice
- Python Users Group (PUG), Afterword
- python-tulip list, Afterword
- Pythonic Card Deck example, A Pythonic Card Deck-A Pythonic Card Deck
- Pythonic objects (see also objects)
- alternative constructor for, An Alternative Constructor
- building user-defined classes, A Pythonic Object
- classmethod versus staticmethod, classmethod Versus staticmethod
- formatted displays, Formatted Displays-Formatted Displays
- further reading on, Further Reading
- hashable Vector2d, A Hashable Vector2d-A Hashable Vector2d
- object representations, Object Representations
- overriding class attributes, Overriding Class Attributes-Overriding Class Attributes
- overview of, Chapter Summary
- private and protected attributes, Private and “Protected” Attributes in Python-Private and “Protected” Attributes in Python
- saving memory with __slots__, Saving Memory with __slots__-Summarizing the Issues with __slots__
- significant changes to, What’s New in This Chapter
- Soapbox discussion, Further Reading-Further Reading
- supporting positional patterns, Supporting Positional Pattern Matching
- topics covered, A Pythonic Object
- Vector2d class example, Vector Class Redux-Vector Class Redux
- Vector2d full listing, Complete Listing of Vector2d, Version 3-Complete Listing of Vector2d, Version 3
- Pythonic sums, Further Reading-Further Reading
- pyuca library, Sorting Unicode Text, Chapter Summary
R
- race conditions, Code for the Multicore Prime Checker
- random.choice function, A Pythonic Card Deck
- recycling (see garbage collection)
- reduce function, Higher-Order Functions-Modern Replacements for map, filter, and reduce
- reducing functions, Vector Take #4: Hashing and a Faster ==, Iterable Reducing Functions-Iterable Reducing Functions
- refactoring strategies
- reference counting, del and Garbage Collection
- registration decorators, Registration Decorators, A Parameterized Registration Decorator-A Parameterized Registration Decorator
- regular expressions, str versus bytes in, str Versus bytes in Regular Expressions
- repr() function, Object Representations
- reserved keywords, (quote …)
- rich comparison operators, Rich Comparison Operators-Rich Comparison Operators
- running averages, computing, Example: Coroutine to Compute a Running Average-Example: Coroutine to Compute a Running Average
S
- S-expression, Scheme Syntax
- salts, What Is Hashable
- Scheme language, Pattern Matching Sequences in an Interpreter-Shortcut syntax for function definition, Scheme Syntax-Scheme Syntax
- SciPy, NumPy-NumPy
- scope
- semaphores, Throttling Requests with a Semaphore-Throttling Requests with a Semaphore
- Sentence classes, Sentence Classes with __iter__-How a Generator Works
- sentinels, Code for the Multicore Prime Checker
- sequence protocol, Programming Ducks-Python Digs Sequences, A Sequence of Words-A Sequence of Words
- sequences
- alternatives to lists, When a List Is Not the Answer-Deques and Other Queues
- further reading on, Further Reading
- list comprehensions and generator expressions, List Comprehensions and Generator Expressions-Tuples Are Not Just Immutable Lists
- list.sort versus sorted built-in, list.sort Versus the sorted Built-In-list.sort Versus the sorted Built-In
- overview of, Chapter Summary
- overview of built-in, Overview of Built-In Sequences-Overview of Built-In Sequences
- pattern matching with, Pattern Matching with Sequences-Shortcut syntax for function definition
- significant changes to, What’s New in This Chapter
- slicing, Slicing-Assigning to Slices
- Soapbox discussion, Further Reading-Further Reading
- topics covered, An Array of Sequences
- tuples, Tuples Are Not Just Immutable Lists-Comparing Tuple and List Methods
- uniform handling of, An Array of Sequences
- unpacking sequences and iterables, Unpacking Sequences and Iterables-Nested Unpacking
- using + and * with, Using + and * with Sequences-A += Assignment Puzzler
- sequences, special methods for
- applications beyond three dimensions, Vector: A User-Defined Sequence Type
- dynamic attribute access, Vector Take #3: Dynamic Attribute Access-Vector Take #3: Dynamic Attribute Access
- __format__, Vector Take #5: Formatting-Vector Take #5: Formatting
- further reading on, Further Reading
- __hash__ and __eq__, Vector Take #4: Hashing and a Faster ==-Vector Take #4: Hashing and a Faster ==
- overview of, Chapter Summary
- protocols and duck typing, Protocols and Duck Typing
- significant changes to, What’s New in This Chapter
- sliceable sequences, Vector Take #2: A Sliceable Sequence-A Slice-Aware __getitem__
- Soapbox discussion, Further Reading-Further Reading
- topics covered, Special Methods for Sequences
- Vector implementation strategy, Vector: A User-Defined Sequence Type
- Vector2d compatibility, Vector Take #1: Vector2d Compatible-Vector Take #1: Vector2d Compatible
- sequential.py program, A Homegrown Process Pool
- server-side web/mobile development, Server-Side Web/Mobile Development
- servers
- setattr function, Special Methods for Attribute Handling
- sets (see also dictionaries and sets)
- shallow copies, Copies Are Shallow by Default-Copies Are Shallow by Default
- shelve module, shelve.Shelf
- simple class patterns, Simple Class Patterns
- single dispatch generic functions, Single Dispatch Generic Functions-Function singledispatch
- Sized interface, Collection API
- slicing
- Soapbox sidebars
- @dataclass, Further Reading
- anonymous functions, Further Reading
- __call__, Further Reading
- code points, Further Reading
- data model versus object model, Further Reading
- design patterns, Further Reading
- duck typing, Further Reading, Further Reading
- dynamic scope versus lexical scope, Further Reading-Further Reading
- equality (==) operator, Further Reading
- explicit self argument, Further Reading
- flat versus container sequences, Further Reading
- __format__, Further Reading
- function-class duality, Further Reading
- functional programming with Python, Further Reading
- generic collections, Further Reading
- inheritance across languages, Further Reading
- interfaces, Further Reading
- key argument, Further Reading
- lis.py and evaluate function, Further Reading
- magic methods, Further Reading
- metaobjects, Further Reading
- minimalistic iterator interface, Further Reading
- mixed-bag lists, Further Reading
- monkey-patching, Further Reading
- multilevel class hierarchies, Further Reading
- mutability, Further Reading
- non-ASCII names in source code, Further Reading
- object destruction and garbage collection, Further Reading
- operator overloading, Further Reading
- Oracle, Google, and the Timbot, Further Reading
- plain text, Further Reading
- pluggable generators, Further Reading-Further Reading
- programming language design, Further Reading
- proper tail calls (PTC), Further Reading-Further Reading
- properties and up-front costs, Further Reading
- protocols as informal interfaces, Further Reading
- Python decorators and decorator design pattern, Further Reading
- Pythonic sums, Further Reading-Further Reading
- safety versus security in private attributes, Further Reading
- static typing, Further Reading
- syntactic sugar, Further Reading
- thread avoidance, Further Reading
- threads-and-locks versus actor-style programming, Concurrency and Scalability Beyond Python-Concurrency and Scalability Beyond Python
- trade-offs of built-ins, Further Reading
- tuples, Further Reading
- Twisted library, Further Reading
- type hints (type annotations), Further Reading-Further Reading
- typing map, Further Reading
- undocumented classes, Further Reading
- Uniform Access Principle, Further Reading-Further Reading
- uvloop, Further Reading
- variance notation in other classes, Further Reading
- with statements, Further Reading
- sorted function, list.sort Versus the sorted Built-In-list.sort Versus the sorted Built-In
- special methods (see also sequences, special methods for)
- advantages of using, A Pythonic Card Deck
- Boolean values of custom types, Boolean Value of a Custom Type
- calling, How Special Methods Are Used
- Collection API, Collection API-Collection API
- emulating numeric types, Emulating Numeric Types-Emulating Numeric Types
- __getitem__ and __len__, A Pythonic Card Deck-A Pythonic Card Deck
- naming conventions, The Python Data Model
- purpose of, The Python Data Model
- special method names (operators excluded), Overview of Special Methods
- special method names and symbols for operators, Overview of Special Methods
- string representation, String Representation
- spinners (loading indicators) (see also network I/O)
- square brackets ([]), A Pythonic Card Deck, List Comprehensions and Readability, Unpacking Sequences and Iterables, Multidimensional Slicing and Ellipsis
- stacked decorators, Memoization with functools.cache
- star (*) operator, Emulating Numeric Types, Using * to Grab Excess Items-Unpacking with * in Function Calls and Sequence Literals, Using + and * with Sequences-A += Assignment Puzzler, From Positional to Keyword-Only Parameters, Overloading * for Scalar Multiplication-Overloading * for Scalar Multiplication
- star equals (*=) operator, Augmented Assignment Operators-Augmented Assignment Operators
- static duck typing, Static Protocols, Interfaces, Protocols, and ABCs, Chapter Summary
- static protocols
- best practices for protocol design, Best Practices for Protocol Design
- definition of, Two Kinds of Protocols
- designing, Designing a Static Protocol-Designing a Static Protocol
- versus dynamic protocols, Protocols and Duck Typing
- extending, Extending a Protocol
- implementing generic static protocols, Implementing a Generic Static Protocol-Implementing a Generic Static Protocol
- limitations of runtime protocol checks, Limitations of Runtime Protocol Checks
- numbers ABCS and numeric protocols, The numbers ABCs and Numeric Protocols-The numbers ABCs and Numeric Protocols
- runtime checkable, Runtime Checkable Static Protocols-Runtime Checkable Static Protocols
- Soapbox discussion, Further Reading
- supporting, Supporting a Static Protocol-Supporting a Static Protocol
- type hints (type annotations), Static Protocols-Static Protocols
- typed double function, The Typed double Function-The Typed double Function
- static typing, Interfaces, Protocols, and ABCs
- staticmethod decorator, classmethod Versus staticmethod
- storage attributes, Terms to understand descriptors
- str() function, String Representation, Object Representations
- str.format() method, What’s New in This Chapter, Formatted Displays
- Strategy pattern, Classic Strategy-Classic Strategy
- strings
- strong testing, Imperfect Typing and Strong Testing
- struct module, What’s New in This Chapter
- structural typing, Structural Typing with ABCs-Structural Typing with ABCs
- structured concurrency, async Beyond asyncio: Curio
- subclassing (see inheritance and subclassing)
- subgenerators, Subgenerators with yield from
- subtype-of relationships, Subtype-of versus consistent-with
- super() function, Vector Take #3: Dynamic Attribute Access, The super() Function-The super() Function
- syntactic sugar, Further Reading
- SyntaxError, SyntaxError When Loading Modules with Unexpected Encoding
- system administration, System Administration
T
- tail call optimization (TCO), Further Reading-Further Reading
- TCP servers, An asyncio TCP Server-An asyncio TCP Server
- TensorFlow, Data Science
- test servers, Downloads with Progress Display and Error Handling
- text files, handling, Handling Text Files-Beware of Encoding Defaults (see also Unicode text versus bytes)
- ThreadingHTTPServer class, ThreadingMixIn and ForkingMixIn
- ThreadingMixIn class, ThreadingMixIn and ForkingMixIn
- threads
- throttling, Throttling Requests with a Semaphore-Throttling Requests with a Semaphore
- Timsort algorithm, Further Reading
- Tkinter GUI toolkit
- tree structures, traversing, Traversing a Tree-Traversing a Tree
- tuples
- classic named tuples, Classic Named Tuples-Classic Named Tuples
- immutability and, Tricks Python Plays with Immutables
- as immutable lists, Tuples as Immutable Lists-Tuples as Immutable Lists
- versus lists, Comparing Tuple and List Methods
- nature of, Further Reading
- as records, Tuples as Records-Tuples as Records
- relative immutability of, The Relative Immutability of Tuples
- simplified memory diagram for, Overview of Built-In Sequences
- tuple unpacking, Tuples as Records
- type hints (type annotations), Tuple Types-Tuples as immutable sequences
- typing.NamedTuple, Typed Named Tuples
- Twisted library, Further Reading
- type casting, Type Casting-Type Casting
- type hints (type annotations)
- annotating positional only and variadic parameters, Annotating Positional Only and Variadic Parameters
- for asynchronous objects, Type Hinting Asynchronous Objects
- basics of, Type Hints 101-Inspecting a class decorated with dataclass
- benefits and drawbacks of, Type Hints in Functions
- flawed typing and strong testing, Imperfect Typing and Strong Testing
- further reading on, Further Reading
- generic type hints for coroutines, Generic Type Hints for Classic Coroutines
- gradual typing, About Gradual Typing-Using None as a Default (see also gradual type system)
- overview of, Chapter Summary
- significant changes to, What’s New in This Chapter
- Soapbox discussion, Further Reading-Further Reading
- supported operations and, Types Are Defined by Supported Operations-Types Are Defined by Supported Operations
- topics covered, Type Hints in Functions
- types usable in, Types Usable in Annotations-NoReturn
- typed double function, The Typed double Function-The Typed double Function
- TypedDict, Data Class Builders, TypedDict-TypedDict
- Typeshed project, Iterable
- TypeVar, Parameterized Generics and TypeVar-The AnyStr predefined type variable
- typing map, The Typing Map, Further Reading (see also type hints (type annotations))
- typing module, Types Usable in Annotations
- typing.NamedTuple, Typed Named Tuples
U
- UCA (see Unicode Collation Algorithm)
- UCS-2 encoding, Basic Encoders/Decoders
- UML class diagrams
- ABCs in collections.abc, ABCs in the Standard Library
- annotated with MGN, Terms to understand descriptors, A Metaclass Solution for Checked
- Command design pattern, The Command Pattern
- django.views.generic.base module, Django Generic Views Mixins
- django.views.generic.list module, Django Generic Views Mixins
- fundamental collection types, Collection API
- managed and descriptor classes, LineItem Take #3: A Simple Descriptor
- MutableSequence ABC and superclasses, Subclassing an ABC
- Sequence ABC and abstract classes, Python Digs Sequences
- simplified for collections.abc, Overview of Built-In Sequences
- simplified for MutableMapping and superclasses, Standard API of Mapping Types
- simplified for MutableSet and superclasses, Set Operations
- Strategy design pattern, Classic Strategy
- Tkinter Text widget class and superclasses, Multiple Inheritance and Method Resolution Order
- TomboList, A Virtual Subclass of an ABC
- unary operators, Unary Operators-Unary Operators
- undocumented classes, Further Reading
- Unicode Collation Algorithm (UCA), Sorting with the Unicode Collation Algorithm
- Unicode literals escape notation (\N{}), Beware of Encoding Defaults
- Unicode sandwich, Handling Text Files
- Unicode text versus bytes
- basic encoders/decoders, Basic Encoders/Decoders-Basic Encoders/Decoders
- byte essentials, Byte Essentials-Byte Essentials
- characters and Unicode standard, Character Issues-Character Issues
- dual-mode str and bytes APIs, Dual-Mode str and bytes APIs-str Versus bytes in os Functions
- further reading on, Further Reading
- handling text files, Handling Text Files-Beware of Encoding Defaults
- normalizing Unicode for reliable comparisons, Normalizing Unicode for Reliable Comparisons-Extreme “Normalization”: Taking Out Diacritics
- overview of, Chapter Summary
- significant changes to, What’s New in This Chapter
- Soapbox discussion, Further Reading
- sorting Unicode text, Sorting Unicode Text-Sorting with the Unicode Collation Algorithm
- topics covered, Unicode Text Versus Bytes
- understanding encode/decode problems, Understanding Encode/Decode Problems-BOM: A Useful Gremlin
- Unicode database, The Unicode Database-Numeric Meaning of Characters
- UnicodeDecodeError, Coping with UnicodeDecodeError
- UnicodeEncodeError, Coping with UnicodeEncodeError
- Uniform Access Principle, Further Reading-Further Reading
- Union type, Optional and Union Types
- unittest module, Hands-On Approach
- unpacking
- user-defined functions, The Nine Flavors of Callable Objects
- UserDict, Subclassing UserDict Instead of dict-Subclassing UserDict Instead of dict
- UTF-8 decoding, How to Discover the Encoding of a Byte Sequence
- UTF-8-SIG encoding, BOM: A Useful Gremlin
- uvloop, Further Reading
V
- variable annotations
- variable scope rules, Variable Scope Rules-Variable Scope Rules
- variables
- variadic parameters, Annotating Positional Only and Variadic Parameters
- variance
- vars([object]) function, Built-In Functions for Attribute Handling
- Vector class, multidimensional
- applications beyond three dimensions, Vector: A User-Defined Sequence Type
- dynamic attribute access, Vector Take #3: Dynamic Attribute Access-Vector Take #3: Dynamic Attribute Access
- __format__, Vector Take #5: Formatting-Vector Take #5: Formatting
- further reading on, Further Reading
- __hash__ and __eq__, Vector Take #4: Hashing and a Faster ==-Vector Take #4: Hashing and a Faster ==
- implementation strategy, Vector: A User-Defined Sequence Type
- overview of, Chapter Summary
- protocols and duck typing, Protocols and Duck Typing
- sliceable sequences, Vector Take #2: A Sliceable Sequence-A Slice-Aware __getitem__
- topics covered, Special Methods for Sequences
- Vector2d compatibility, Vector Take #1: Vector2d Compatible-Vector Take #1: Vector2d Compatible
- Vector2d
- vectors
- virtual attributes, Dynamic Attributes and Properties
- virtual subclasses, A Virtual Subclass of an ABC-A Virtual Subclass of an ABC
W
- Walrus operator (:=), List Comprehensions and Readability
- weak references, del and Garbage Collection
- Web Server Gateway Interface (WSGI), WSGI Application Servers
- web/mobile development, Server-Side Web/Mobile Development
- with, match, and else blocks
- context managers and with blocks, Context Managers and with Blocks-Using @contextmanager
- else clause, Do This, Then That: else Blocks Beyond if-Do This, Then That: else Blocks Beyond if
- further reading on, Further Reading
- overview of, Chapter Summary
- pattern matching in lis.py, Pattern Matching in lis.py: A Case Study-Using OR-patterns
- purpose of with statements, Context Managers and with Blocks
- significant changes to, What’s New in This Chapter
- Soapbox discussion, Further Reading-Further Reading
- topics covered, with, match, and else Blocks