1

I just learned there is a walrus operator in Python 3.8

if a := 2 + 3:
    print(a) # 5

I wonder why they created a new operator instead of allowing the existing assignment operator as expression, like

(code that throws a SyntaxError follows)

if a = 2 + 3: # assign 2 + 3 to a, then evaluate the trueness of a
    print(a) # 5

Edit: I saw this question, but that does not specifically address why we can't use the existing = operator in place of :=.

Randy Sugianto 'Yuku'
  • 71,383
  • 57
  • 178
  • 228

0 Answers0