Skip to main content Brad's PyNotes

Posts on PEP

  1. PEP 544: Protocols - Structural Subtyping (Static Duck Typing)

    TL;DR

    PEP 544 introduces Protocol classes that enable structural subtyping (static duck typing) - type checking based on what methods an object has rather than its inheritance hierarchy, making Python’s type system more flexible and duck-typing friendly.

  2. PEP 526: Variable Annotations - Type Hints for Variables

    TL;DR

    PEP 526 introduced variable annotations in Python 3.6, allowing type hints for variables using the syntax variable: type = value, extending PEP 484’s function annotations to all variables for better code documentation and static analysis.

  3. PEP 572: The Walrus Operator - Assignment Expressions in Python

    TL;DR

    PEP 572 introduced the walrus operator (:=) in Python 3.8, allowing assignment within expressions to reduce code duplication and improve readability.

    Interesting!

    The walrus operator gets its name from its resemblance to a walrus face - the colon represents the eyes and the equals sign represents the tusks!

  4. PEP 8: The Python Style Guide That Rules Them All

    TL;DR

    PEP 8 defines Python’s official coding style guide, emphasizing readability with 4-space indentation, descriptive naming conventions, and the principle that “code is read much more often than it is written.”