'skipping a function if returned value is None?

Is there anyway to avoid a function call if function returns None? I'm doing this at the moment, but it seems very inefficient calling the function twice

if  bool(runChecks(problems)):
    return  runChecks(problems)

I would rather do this in one line of code, instead of calling it twice. If it returns True, then it returns a string with the error.

If it returns false, then it continues with the rest of the program. The runChecks() is a function that makes sure input is viable for program. no letters or chars that I havnt programmed it for



Solution 1:[1]

Try the walrus operator

if val:=runChecks(problems):
    return val

Solution 2:[2]

value = runChecks(problems)
if value:
    return value

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dumbPotato21
Solution 2 little_birdie