TABLE OF CONTENTS Copyright Preface 1. Introduction 2. Python Programs 2.1. File/Text Input 2.2. Interactive Mode 3. Program Execution 3.1. Code Blocks 3.2. Name Binding 3.3. Scope 3.3.1. Function definition block 3.3.2. Class definition block 3.3.3. The global declaration 3.3.4. The nonlocal declaration 3.4. Scope Examples (Optional) 3.5. Program Start and Termination 3.6. Exceptions 4. Packages & Modules 4.1. Modules 4.1.1. The import statement 4.2. Packages 4.2.1. Regular packages 4.2.2. Namespace packages 4.3. Package Relative Imports 5. Python Source Code 5.1. Line Structure 5.1.1. Logical lines 5.1.2. Physical lines 5.1.3. Comments 5.1.4. Blank Lines 5.1.5. Physical line joining 5.1.6. Indentations 5.2. Tokens 5.3. Identifiers and Keywords 5.3.1. Keywords 5.3.2. Reserved classes of identifiers 5.4. Literals 5.4.1. String and bytes literals 5.4.2. Formatted string literals 5.4.3. String literal concatenation 5.4.4. Numeric literals 5.5. Compound Type Literals 5.6. Operators 5.7. Delimiters 6. Objects 6.1. Identities 6.2. Attributes 6.3. Types 6.4. Builtin type Function 6.5. Mutable vs Immutable Types 6.6. Constructors 6.7. Boolean Context 6.8. Lifetime of an Object 7. Simple Types 7.1. None 7.2. NotImplemented 7.3. Ellipsis 7.4. Numbers 7.4.1. Integers (numbers.Integral) 7.4.2. Real numbers (numbers.Real) 7.4.3. Complex numbers (numbers.Complex) 8. Compound Types 8.1. Tuples, Lists, Sets, and Dictionaries 8.1.1. Constructors 8.1.2. Literal syntax 8.1.3. Comprehensions 8.2. Sequences 8.2.1. Sequence unpacking 8.3. Immutable Sequences 8.3.1. Strings 8.3.2. Tuples 8.3.3. Bytes sequences 8.4. Mutable Sequences 8.4.1. Lists 8.4.2. List comprehension 8.4.3. Byte arrays 8.5. Set Types 8.5.1. Sets 8.5.2. Set comprehension 8.5.3. Frozen sets 8.6. Mappings 8.6.1. Dictionaries 8.6.2. Dictionary comprehension 8.6.3. Element insertion/deletion 9. Expressions 9.1. Expression Lists 9.2. Evaluation Order 9.3. Assignment Expressions 9.4. Conditional Expressions 9.5. Arithmetic Conversions 9.6. Arithmetic Operations 9.6.1. Unary arithmetic operators 9.6.2. Binary arithmetic operators 9.6.3. The power operator 9.7. Bitwise Operations 9.7.1. Unary bitwise operator 9.7.2. Binary bitwise operators 9.7.3. The shift operators 9.8. Boolean Operations 9.8.1. The not operator 9.8.2. The and operator 9.8.3. The or operator 9.9. Comparisons 9.9.1. Identity comparisons 9.9.2. Value comparisons 9.9.3. Membership test operations 10. Simple Statements 10.1. Expression Statement 10.2. Assignment Statement 10.2.1. Augmented Assignment Statements 10.3. The pass Statement 10.4. The return Statement 10.5. The raise Statement 10.6. The break Statement 10.7. The continue Statement 10.8. The global Statement 10.9. The nonlocal Statement 10.10. The del Statement 10.11. The assert Statement 10.11.1. The basic form 10.11.2. The extended form 11. Compound Statements 11.1. The if - elif - else Statement 11.2. The while - else Statement 11.3. The for - in - else Statement 11.3.1. The range function 11.3.2. The enumerate function 11.4. The try Statement 11.5. The with Statement 12. Pattern Matching 12.1. The match - case Statement 12.2. Patterns 12.2.1. The wildcard pattern 12.2.2. Literal patterns 12.2.3. Value patterns 12.2.4. Group patterns 12.2.5. Capture patterns 12.2.6. OR patterns 12.2.7. AS patterns 12.2.8. Sequence patterns 12.2.9. Mapping patterns 12.2.10. Class patterns 13. Functions 13.1. Function Definition 13.2. Function Parameters 13.3. Optional Parameters 13.4. "Varargs" Functions 13.5. Function Call 13.5.1. Calls 13.5.2. Callable 13.5.3. Positional vs keyword arguments 13.6. Lambda Expressions 13.7. map, filter, and reduce 13.7.1. The map function 13.7.2. The filter function 13.7.3. The functools.reduce function 13.8. Function Decorators 13.8.1. Built-in decorators 14. Classes 14.1. Class Definition 14.2. Classes and Instances 14.2.1. Class objects 14.2.2. Class variables 14.2.3. Constructors 14.2.4. The __init__ function 14.2.5. Instance objects 14.2.6. Instance variables 14.2.7. Instance methods 14.3. Object Oriented Programming 14.3.1. Data encapsulation 14.3.2. Magic methods 14.3.3. Inheritance 14.3.4. Multiple inheritance 14.3.5. super() 14.3.6. Duck typing 14.4. Data Classes 14.5. Enums 14.6. Class Decorators 15. Coroutines & Asynchronous Programming 15.1. Generators 15.1.1. Iterators 15.1.2. Generator functions 15.2. yield Expressions 15.3. Generator Expressions