This is actually even more important: For a clear semantic we need some way to distinguish declaration and assignment: What does a = 42
mean? Is it:
- Creating a new binding
a
with the value42
? - Assigning the existing
a
with the value42
?
Python got this wrong, where the compiler doesn’t know and where it is ambiguous would exit with an UndefinedLocalError
. So they had to add global
and nonlocal
as declaration to tell the compiler what the meaning of the subsequent a = 42
is.
So yes, it is less writing, but the let
is imporant. One could attempt to avoid the in
and make it implied (something like let a = b and b = 42 a
) but it can be somewhat confusing.