PEP 485: A Function for Testing Approximate Equality
TL;DR
PEP 485 introduced math.isclose()
to solve the fundamental problem of comparing floating-point numbers by testing if two values are “approximately equal” rather than exactly equal.
PEP 485 introduced math.isclose()
to solve the fundamental problem of comparing floating-point numbers by testing if two values are “approximately equal” rather than exactly equal.
PEP 465 introduced the @ operator for matrix multiplication, solving a major readability problem in scientific Python code by providing a dedicated operator that makes mathematical formulas translate directly into code.
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.
PEP 1 defines the purpose, format, and workflow for Python Enhancement Proposals (PEPs) - the formal mechanism for proposing new features, processes, and standards for the Python language and community.
PEP 274 introduced dictionary comprehensions in Python 2.7/3.0 with syntax {key: value for item in iterable}
, providing a concise way to create dictionaries similar to list comprehensions.
PEP 308 introduced conditional expressions in Python 2.5 with the syntax value_if_true if condition else value_if_false
, providing a concise way to assign values based on conditions.
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.
PEP 289 introduced generator expressions in Python 2.4, providing memory-efficient alternatives to list comprehensions using lazy evaluation with syntax (expression for item in iterable if condition)
.
PEP 484 introduced type hints to Python, enabling static type checking with tools like mypy while maintaining runtime flexibility and improving code documentation and IDE support.
PEP 20 presents the “Zen of Python” - 19 guiding principles that capture Python’s design philosophy, emphasizing readability, simplicity, and explicit over implicit approaches.
PEP 343 introduced the ‘with’ statement for automatic resource management, ensuring cleanup code runs even when exceptions occur, making file handling and resource management safer and cleaner.
PEP 572 introduced the walrus operator (:=) in Python 3.8, allowing assignment within expressions to reduce code duplication and improve readability.
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!
PEP 498 introduced f-strings (formatted string literals) in Python 3.6, allowing direct expression embedding in strings with f"Hello {name}" syntax, making string formatting more readable and performant.
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.”