'Is there a way to combine statements if & as in python? [duplicate]
I have been just wondering if it is possible to somehow combine 'if' and 'as' statements like this:
if possible_error() as error:
return error
instead of
error = possible_error()
if error:
return error
where 'possible_error' function returns either empty string or error message. By doing so I could save one line of code.
I know that some compromise is to run this function twice:
if possible_error():
return possible_error()
but I would rather avoid doing this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
