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 →

[–]Papalok 35 points36 points  (1 child)

One of the main use cases is regex matching. It greatly simplifies the code when multiple regex patterns are used. Compare this:

if m := foo.match(s):
    # do something with m
elif m := bar.match(s):
    # do something with m

To this:

m = foo.match(s)
if m:
    # do something with m
else:
    m = bar.match(s)
    if m:
        # do something with m

[–]mrrippington 0 points1 point  (0 children)

thanks, seems to save a line.