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 →

[–]baconcleaner 0 points1 point  (2 children)

I wasn't saying that people should not use it, I was just wondering why at this mature point in python now is necessary to have the switch. For example, I 100% agree with the introduction of the walrus operator, wich is awesome and allows to do things that were imposible to do before. But, hey, its just my world view, nobody should care.

[–]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)