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
CodePudding user response:
Try the walrus operator
if val:=runChecks(problems):
return val
CodePudding user response:
value = runChecks(problems)
if value:
return value