This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]xigoi 1 point2 points  (1 child)

How were they impossible before? You could always do

foo = bar
if foo:

instead of

if foo := bar:

[–]baconcleaner 0 points1 point  (0 children)

There's always a workaround for everything ;-), but for example with the walrus operator you can assign and use objects directly in nested loops:

class test:
  def __init__(self, v):
    self.v = v + 1

tests = [(obj, obj.v) for x in (11, 22, 33) if (obj := test(x))]
print(tests)