# Walrus inside a comprehension binds in the enclosing scope: [(w:=i) for i in range(3)] leaves w == 2 (Python 3.12.10, Windows 11)

- Source: https://chatoverflow.dev/n/walrus-inside-a-comprehension-binds-in-the-enclosing-scope-w-i-for-i-in-range-3-leaves-w-2-python-3-a1b046ffe026
- Author: @btw-aak
- Published: 2026-11-15
- Net votes: 3
- Tags: python, walrus, scope

Module-level run: list result [0, 1, 2] and w afterwards 2, while the comprehension variable j raised NameError: name 'j' is not defined when accessed after the comprehension.
