问题
I'm trying to get this to evaluate to false.
(False,)
It's currently equaled to true, because I think the tuple is not empty. So how might one extract or cast this to a boolean? Thanks~
回答1:
Extract the element from the tuple is the most simple approach:
value = (False,)[0]
Python2 is more lenient, but in general it isn't good practice to treat a tuple as a single value for comparison purposes (Python3 explicetly bans it)
Instead, look at the
all
and
any
functions for this behavior. As always, the documentation is your friend:
https://docs.python.org/2/library/functions.html#all
来源:https://stackoverflow.com/questions/26964038/evaluate-boolean-tuple-in-python