Why can't Python's walrus operator be used to set instance attributes?
问题 I just learned that the new walrus operator ( := ) can't be used to set instance attributes, it's supposedly invalid syntax (raises a SyntaxError ). Why is this? (And can you provide a link to official docs mentioning this?) I looked through PEP 572, and couldn't find if/where this is documented. Research This answer mentions this limitation without an explanation or source: you can't use the walrus operator on object attributes Sample Code class Foo: def __init__(self): self.foo: int = 0 def