Browse by Topic

Popular

Latest

Latest Python Posts

Illustration comparing dynamic and static typing in Python with a balance scale and type annotations.
Python

Python Dynamic Typing vs Static Typing: When to Use Each

Learn the practical differences between Python's dynamic typing and static type checking, including runtime behavior, type hints, mypy, and when each approach is the right fit.

dynamic typingstatic typingtype hintsmypy
Illustration of Python strong typing with type hints and static type checking.
Python

Python Strong Typing: Type Hints and Static Checks

Understand what strong typing means in Python, how type hints and static checkers like mypy help catch type errors, and when runtime validation is needed.

type hintsmypystatic typingduck typing
Illustration of a Python variable name binding to different object types at runtime, showing dynamic typing
Python

Understanding Python Dynamic Typing at Runtime

Learn how Python's dynamic typing binds names to objects at runtime, why type hints don't enforce types, and how static and runtime checks can manage the tradeoffs.

dynamic typingduck typingtype hintsruntime dispatch
A diagram showing a variable name being hidden by an inner scope in Python, with overlapping scopes and a shadow effect.
Python

Python Variable Shadowing Explained with Examples

Learn how Python variable shadowing works, why it can cause subtle bugs, and how to avoid it with clear naming and scoping discipline.

pythonvariable scopename resolutionLEGB rule
Diagram showing local and nonlocal variable scope in Python nested functions
Python

Python Local vs Nonlocal Variable: Scope Explained

Understand how Python resolves local and nonlocal variables in nested functions, when to use the nonlocal keyword, and how it differs from global.

Pythonvariable scopenonlocalclosures
Illustration contrasting a local variable inside a function with a global variable at module level in Python
Python

Python Local vs Global Variable: Scope Explained

Understand how Python local and global variables differ, how assignment creates local variables, and when to use the global and nonlocal keywords.

PythonVariable ScopeGlobal VariablesLEGB Rule
Illustration of Python nonlocal keyword showing nested function scope and variable binding.
Python

Python nonlocal keyword: scope and closures

Learn how Python's nonlocal keyword works, when to use it in nested functions, and how it differs from global and local scope.

Pythonscopeclosuresnested functions
Editorial thumbnail showing a Python function box with a variable binding arrow pointing outside the function scope to a module-level container.
Python

How the Python Global Keyword Affects Function Scope

Explains how the Python global keyword changes name resolution inside functions, when it is required, and where nonlocal or return values are better alternatives.

global keywordpython scopenonlocalmodule-level variables
Illustration of a nested function in Python modifying an outer variable using the nonlocal keyword, shown as a scope diagram.
Python

Python Nonlocal Variable: Scope and Usage

Understand the Python nonlocal variable keyword, its role in nested functions, and practical examples for closures.

nonlocalclosuresnested functionsvariable scope
Python code editor showing a global variable being accessed from inside a function with the global keyword highlighted.
Python

Python Global Variables: Scope, Syntax, and Pitfalls

python global variable: Learn how Python global variables work: the global keyword, LEGB scope resolution, mutable object traps, thread safety, and when to avoid them.

python scopeglobal keywordvariable scopingmodule-level state