如果t,如果== True,有什么区别?

时间:2018-11-02 16:48:37

标签: python python-3.x

以下返回[1]

def compact(listy):
    truth_list = [t for t in listy if t == True]
    return truth_list

print(compact([0,1,2,"",[], False, {}, None, "All done"]))

以下返回所需的结果,所有真值:[1、2,“全部完成”]

def compact(listy):
    truth_list = [t for t in listy if t]
    return truth_list

print(compact([0,1,2,"",[], False, {}, None, "All done"]))

我对为什么t == True只返回[1]感到困惑

0 个答案:

没有答案