How do I check all variables returned buy the functions exists
Steve D'Aprano
steve+python at pearwood.info
Fri Sep 15 20:58:06 EDT 2017
On Sat, 16 Sep 2017 01:43 am, Ganesh Pal wrote:
> I have a function that return's x variables How do I check if all the the
> values returned are not None/False/0/''
[...]
> value1, value2 , value3 = return_x_values()
>
>
> # check if its not none
>
> # I think this can be better
> if value1 and value2 and value3 :
> print "continue with the program"
values = return_x_values()
if all(values):
print "continue"
else:
print "at least one value was falsey"
If you want to test for None specifically:
if any(v is None for v in values):
print "at least one value was None"
--
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.
More information about the Python-list
mailing list