Welcome to Python Deep Dive, a comprehensive repository designed to take you on a journey through the entire spectrum of Python programming. This repository is structured to guide you from the fundamentals, through object-oriented programming (OOP), into data structures and algorithms, advanced Python concepts, and finally to the 23 classic design patterns. Additionally, it includes insights into CPython compilation to help you become a Python contributor.
- Fundamentals
- Object-Oriented Programming (OOP)
- Data Structures
- Algorithms
- Design Patterns
- Advanced Python Deep Dive
- Compiling CPython
- Contributing
- License
In this section, you'll learn the basics of Python, including:
- Syntax and structure
- Data types and variables
- Control flow (loops and conditionals)
- Functions and modules
- Error handling and exceptions
Start here if you're new to Python or need a refresher on the basics.
This section dives into OOP concepts in Python. You'll explore:
- Classes and objects
- Inheritance and polymorphism
- Encapsulation and abstraction
- Dependency injection
- Class-level and instance-level attributes
Learn how to design robust object-oriented applications in Python.
Here, you'll discover the built-in and custom data structures used in Python, including:
- Lists, tuples, sets, and dictionaries
- Stacks and queues
- Linked lists
- Trees and graphs
- Heaps and hash tables
Understanding these structures is crucial for building efficient and scalable applications.
In this section, you'll find various algorithms implemented in Python, covering:
- Sorting algorithms (bubble sort, quicksort, mergesort, etc.)
- Searching algorithms (binary search, linear search, etc.)
- Recursion and iterative solutions
- Graph traversal algorithms (DFS, BFS, Dijkstra's algorithm, etc.)
- Dynamic programming and greedy algorithms
These algorithms form the backbone of many computer science problems and interview questions.
Finally, explore the 23 classic design patterns from the "Gang of Four," with Python implementations, including:
- Creational patterns (Singleton, Factory, Builder, Prototype, Abstract Factory)
- Structural patterns (Adapter, Composite, Bridge, Decorator, Facade, Flyweight, Proxy)
- Behavioral patterns (Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor)
Learn how these patterns can be applied to solve common software design challenges.
In this section, you'll delve into advanced topics to deepen your understanding of Python:
- The Python Data Model
- A Pythonic Card Deck
- How Special Methods Are Used
- Emulating Numeric Types
- String Representation
- Boolean Value of a Custom Type
- Collection API
- Overview of Special Methods
- Why
len
Is Not a Method
- An Array of Sequences
- Overview of Built-In Sequences
- List Comprehensions and Generator Expressions
- Tuples as Records and Immutable Lists
- Pattern Matching with Sequences
- Slicing
- Arrays, Memory Views, and NumPy
- Deques and Other Queues
- Dictionaries and Sets
- Modern
dict
Syntax - Pattern Matching with Mappings
- Practical Consequences of How
dict
and Sets Work
- Modern
- Unicode Text Versus Bytes
- Character Issues
- Byte Essentials
- Handling Text Files
- Normalizing Unicode for Reliable Comparisons
- Data Class Builders
- Overview of Data Class Builders
- Classic Named Tuples and Typed Named Tuples
- More About
@dataclass
- Object References, Mutability, and Recycling
- Variables Are Not Boxes
- Identity, Equality, and Aliases
- Shallow and Deep Copies
- Garbage Collection
- Functions as First-Class Objects
- Treating a Function Like an Object
- Higher-Order Functions
- Modern Replacements for
map
,filter
, andreduce
- Anonymous Functions
- User-Defined Callable Types
- Type Hints in Functions
- About Gradual Typing
- Starting with Mypy
- Types Usable in Annotations
- Static Protocols
- Decorators and Closures
- Decorators 101
- Variable Scope Rules
- Closures and the
nonlocal
Declaration - Implementing a Simple Decorator
- Memoization with
functools.cache
- Design Patterns with First-Class Functions
- Case Study: Refactoring Strategy
- Function-Oriented Strategy
- The Command Pattern
- A Pythonic Object
- Object Representations
- Formatted Displays
- A Hashable Vector2d
- Saving Memory with
__slots__
- Special Methods for Sequences
- Vector: A User-Defined Sequence Type
- Protocols and Duck Typing
- Vector Take #4: Hashing and a Faster
==
- Interfaces, Protocols, and ABCs
- Two Kinds of Protocols
- Defensive Programming and “Fail Fast”
- Structural Typing with ABCs
- Inheritance: For Better or for Worse
- The
super()
Function - Multiple Inheritance and Method Resolution Order
- Coping with Inheritance
- The
- More About Type Hints
- Overloaded Signatures
- Variance and Generic Types
- Operator Overloading
- Operator Overloading 101
- Rich Comparison Operators
- Iterators, Generators, and Classic Coroutines
- Using
iter
with a Callable - Generator Functions in the Standard Library
- Classic Coroutines
- Using
- with, match, and else Blocks
- Context Managers and
with
Blocks - Pattern Matching in lis.py: A Case Study
- Context Managers and
- Concurrency Models in Python
- Processes, Threads, and Python’s Infamous GIL
- Spinner with Threads, Processes, and Coroutines
- Concurrent Executors
- Concurrent Web Downloads
- Launching Processes with
concurrent.futures
- Asynchronous Programming
- An asyncio Example: Probing Domains
- Downloading with asyncio and HTTPX
- Dynamic Attributes and Properties
- Data Wrangling with Dynamic Attributes
- Flexible Object Creation with
__new__
- Using a Property for Attribute Validation
- Attribute Descriptors
- Descriptor Example: Attribute Validation
- Overriding Descriptors
- Class Metaprogramming
- Classes as Objects
- type: The Built-In Class Factory
- Metaclasses
In this section, you'll learn about contributing to Python by compiling CPython:
- Compiling CPython
- Compiling CPython on macOS
- Compiling CPython on Linux
- Installing a Custom Version
- A Quick Primer on Make
- CPython’s Make Targets
- Compiling CPython on Windows
- Profile-Guided Optimization
- The Python Language and Grammar
- Why CPython Is Written in C and Not Python
- The Python Language Specification
- The Parser Generator
- Regenerating Grammar
- Configuration and Input
- Configuration State
- Build Configuration
- Building a Module From Input
- Lexing and Parsing With Syntax Trees
- Concrete Syntax Tree Generation
- The CPython Parser-Tokenizer
- Abstract Syntax Trees
- Example: Adding an Almost-Equal Comparison Operator
- The Compiler
- Instantiating a Compiler
- Core Compilation Process
- Assembly
- Creating a Code Object
- Example: Implementing the Almost-Equal Operator
- The Evaluation Loop
- Constructing Thread State
- Frame Execution
- The Value Stack
- Example: Adding an Item to a List
- Memory Management
- Memory Allocation in C
- The CPython Memory Allocator
- Reference Counting
- Garbage Collection
- Parallelism and Concurrency
- Models of Parallelism and Concurrency
- Multiprocess Parallelism
- Multithreading
- Asynchronous Programming
- Objects and Types
- Built-in Types
- Object and Variable Object Types
- The
type
Type - The Unicode String Type
- The Dictionary Type
- The Standard Library
- Python Modules
- Python and C Modules
- The Test Suite
- Running the Test Suite on Various OS
- Test Flags and Utilities
- Debugging
- Using the Crash Handler
- Compiling Debug Support
- Using Debuggers (LLDB, GDB, Visual Studio, CLion)
- Benchmarking, Profiling, and Tracing
- Using
timeit
for Microbenchmarks - Using
- Using
the Python Benchmark Suite for Runtime Benchmarks
- Profiling Python Code with cProfile
- Profiling C Code with DTrace
14. Next Steps
- Writing C Extensions for CPython
- Improving Your Python Applications
- Contributing to the CPython Project
15. Appendix: Introduction to C for Python Programmers
- The C Preprocessor
- Basic C Syntax
Contributions are welcome! If you'd like to contribute to this repository, please follow these steps:
- Fork this repository.
- Create a new branch with your changes.
- Open an issue first to discuss the changes you want to make.
- After the discussion, submit a pull request with a detailed explanation of your contribution.
For major changes, please ensure that the issue is thoroughly discussed before starting the implementation.
This project is licensed under the MIT License. See the LICENSE file for details.
Thank you for exploring Python Deep Dive! If you have any questions, suggestions, or feedback, feel free to open an issue or contact.
Regards: Muhammad Hashim