Pages

Topics

Tools

↑↓navigate↵openescclose

Python guides

Every published Python guide, newest first, with practical examples you can copy into your own project.

3,965 guides across 14 topics

Topics

Latest Python guides

Illustration of Python membership operators checking if an item exists in a collection.
Python

Python Membership Operators: in and not in

Learn how Python's in and not in operators test membership across lists, strings, dictionaries, and sets, including performance trade-offs and edge cases.

membership operatorspython syntaxin operatornot in operator
Diagram showing two Python objects with different identity but equal values, illustrating `is` vs `==`.
Python

Python Object Identity: How `is` and `id()` Work

Learn how Python object identity works, what `id()` and `is` actually check, and when to use identity checks instead of equality comparisons.

object identityis operatorid()python internals
Two Python objects compared with == and is, showing value vs identity
Python

Python == vs is: When to Use Each

Python's == compares values, while is compares object identity. This article explains when to use each, with code examples and best practices for correctness and readability.

Python equalityobject identityPython operatorsNone comparison
Two distinct objects in memory with an arrow showing the is not operator checking reference inequality in Python
Python

Python `is not` Operator: Identity vs Equality

Understand Python's `is not` operator, how it differs from `!=`, and when to use it for identity checks with None and singletons.

Pythonidentity comparisonequalityNone
Illustration of Python is operator comparing two objects by identity, with a scale showing identity vs equality.
Python

Python is Operator: Identity vs Equality

Learn how Python's `is` operator checks object identity, when to use it instead of `==`, and common pitfalls with integer interning, string caching, and singletons.

identity comparisonequalityobject identityPython syntax
Illustration of Python comparison chaining with three values in a chain, showing the single-evaluation behavior.
Python

Python Comparison Chaining: Syntax, Behavior, and Pitfalls

Learn how Python comparison chaining works, how expressions like a < b < c are evaluated, and when to prefer the chained form over explicit and.

Pythoncomparison operatorschainingsyntax
Diagram showing a chained comparison expression in Python with three values and two comparison operators.
Python

Python Chained Comparison: Syntax and Behavior

Learn how Python's chained comparisons work, including evaluation semantics, short-circuiting, and practical use cases for cleaner conditionals.

chained comparisonpython syntaxcomparison operatorsshort-circuit evaluation
Diagram showing Python less than operator comparing two values with a left-to-right arrow.
Python

Python Less Than Operator: Syntax and Comparison Behavior

Understand how Python's less than operator works for numbers, strings, and custom objects, including chaining, overloading, and common pitfalls.

comparison operatorsPython syntaxoperator overloadingconditional logic
Illustration of two data blocks compared with a greater-than symbol, representing the Python comparison operator.
Python

Python Greater Than Operator: Usage and Pitfalls

Learn how Python's greater-than operator compares numbers, strings, sequences, sets, and custom objects, including chained comparisons and common pitfalls.

comparison operatorsPython syntaxoperator overloadingchained comparisons
Python code comparing two variables with the != operator, highlighting inequality
Python

Python != Operator: Usage and Common Pitfalls

python != operator: Learn how the Python != operator works, how it differs from 'is not', and how to avoid common mistakes when comparing values in real code.

Python operatorscomparison operatorsinequalityPython syntax