(Apr-22-2021, 12:22 AM)Skaperen Wrote: how would you feel if Python's assignment operator was := instead of just = ?Would have been incredibly silly change now as it has been
=
since the start.As
:=
was free added in Python 3.8(🐳rus operator) >>> print(num = 99) Traceback (most recent call last): File "<interactive input>", line 1, in <module> TypeError: 'num' is an invalid keyword argument for print() # Walrus power >>> print(num := 99) 99Saves us from calling
len()
twice.lst = [1, 2, 3, 4] if (n := len(lst)) > 3: print(f"List is too long <{n} elements,need to be <= 3>")
Output:List is too long <4 elements,need to be <= 3>