任何人都可以解釋什麼是在這個代碼布萊恩?Python:搜索到列表失敗
def some_function(value):
my_list = [value, [True, "Some text"]]
if True in my_list:
return "yes"
else:
return "no"
>>> print(function(1))
yes
>>> print(function("1"))
no
值= 1,我得到了 「是」,這種行爲是正確的。但如果值是一些字符串,結果是「否」。我認爲這應該永遠是「是」。我用Python3.4
@Tichodroma:標題編輯錯了 - 問題說_ _「」值= 1,我得到了「是」,這種行爲是正確的「_,暗示問題的問題不是爲什麼1 == True' – Eric
@Eric 。同意。但目前的標題也是錯誤的。該清單與問題無關。 –
'True'不在'my_list'中,而是在'my_list [1]'中。 –