It is not syntactic sugar, "x := 10" is an assignment expression in contrast with "x = 10", which is a statement.
Hence the former can be used in contexts like "if x := 10: pass", which is the whole point of the PEP.
replies(2):
Hence the former can be used in contexts like "if x := 10: pass", which is the whole point of the PEP.
For example, import mod is NOT defined as
mod = eval(open("mod.py").read())
but involves abstract load module operation, which is dependant on the environment.That's why := is just syntactic sugar; there are no new semantics.
Just for fun, this seems to work:
(locals().pop('x', None), locals().setdefault('x', y))[1]