Browse by Topic

Popular

Latest

Latest Python Posts

Diagram showing local variable scope inside a function, with global scope outside.
Python

Python Local Variable Scope: How It Works

Understand how Python local variables work: scope resolution, lifetime, closures, and common errors like UnboundLocalError.

pythonvariable scopeLEGB ruleclosures
Illustration of Python variable scope showing nested scopes and name resolution order.
Python

Python Variable Scope: LEGB, global, and nonlocal

Learn how Python resolves names with the LEGB rule and how to use global and nonlocal to modify variables in module-level and enclosing scopes.

Pythonvariable scopeLEGB ruleclosures
Editorial illustration of Python variable naming showing valid and invalid identifier examples with underscore and keyword symbols.
Python

Python Variable Naming Rules and Conventions

Understand Python's identifier syntax, reserved keywords, built-in shadowing, and PEP 8 naming conventions so your variable names are legal, clear, and maintainable.

python identifiersPEP 8naming conventionscode quality
Illustration of two variables exchanging positions in Python using tuple unpacking, with a clean code editor background.
Python

How to Swap Variables in Python with Tuple Unpacking

Learn how to swap variables in Python with tuple unpacking, including evaluation order, list swaps, edge cases, and when a temporary variable is still useful.

tuple unpackingvariable assignmentpython idiomscode readability
Illustration showing two variables exchanging values through a bidirectional swap arrow, representing Python multiple assignment
Python

Python Multiple Assignment: Syntax and Behavior

Python's multiple assignment evaluates the right side before assigning. This article covers variable swapping, iterable unpacking, star expressions, and common failure cases.

multiple assignmenttuple unpackingpython syntaxvariable swapping
Diagram showing Python variable initialization with None and empty list options.
Python

Python Variable Initialization: Avoiding Common Pitfalls

python variable initialization: Learn how to initialize Python variables correctly, avoid mutable default pitfalls, and choose between None, empty values, and type hints.

Pythonvariable initializationNonetype hints
Illustration of Python variable names bound to shared objects, showing reference semantics versus value copying.
Python

Python Variable Assignment: Names, References, and Mutability

Understand how Python variable assignment binds names to objects, why rebinding differs from mutation, and how aliasing affects real code.

pythonvariable assignmentreference semanticsmutability
Illustration of Python variable declaration with type hints and scope
Python

Python Variable Declaration: Syntax and Scope

python variable declaration: Understand Python variable declaration: dynamic typing, type hints, scope, and best practices for clean, maintainable code.

PythonType HintsVariable ScopeDynamic Typing