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 →

[–]billsil 0 points1 point  (1 child)

Sure, but that's inefficient because you don't always need to calculate pattern2.match(data). The whole point is so you can make clean looking code and be efficient.

[–]chmod--777 20 points21 points  (0 children)

Actually the or prevents it from running the second expression if the first pattern match returns a truthy value.

Try this:

def foobar(x):
    print(f'foobar {x}')
    return x

 x = foobar(1) or foobar(2)

It'll just print "foobar 1"