["python","if-statement"]
Pythonic way to avoid "if x: return x" statements

I have a method that calls 4 other methods in sequence to check for specific conditions, and returns immediately (not checking the following ones) whenever one returns something Truthy. def check_all_conditions(): x = check_size() if x: return x x = check_color() if x: return x x = check_tone() if x: return x x = check_flavor() if x: return x return None This seems like a lot of baggage code. Instead of each 2-line if statement, I'd rather do something like: x and return x But that is invalid Python. Am I missing a simple, elegant solution here? Incidentally, in this situation, those four check methods may be expensive, so I do not want to call them multiple times.
You could use a loop: conditions = (check_size, check_color, check_tone, check_flavor) for condition in conditions: if result := condition(): return result This has the added advantage that you can now make the number of conditions variable. Note that the above example uses an assignment expression (aka the walrus expression) to integrate the asignment and result test; this requires Python 3.8 or newer. You could use map() + filter() to get the first such matching value, and, as of Python 3.11, operator.call(): try: # python 3.11 from operator import call except ImportError: # older versions def call(callable): return callable() conditions = (check_size, check_color, check_tone, check_flavor) return next(filter(None, map(call, conditions)), None) but if this is more readable is debatable. Another option is to use a generator expression: conditions = (check_size, check_color, check_tone, check_flavor) checks = (condition() for condition in conditions) return next((check for check in checks if check), None)