比较真假混淆

发布于 2021-01-29 14:55:14

我对分配给False,True的测试值感到困惑

要检查真实值,我们只需

a = True
if (a):

假怎么样?

a=False
if (a) <--- or should it be if (a==False), or if not a ?
关注者
0
被浏览
277
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    Python样式指南中

    对于序列(字符串,列表,元组),请使用空序列为假的事实。

    Yes: if not seq:
         if seq:
    
    No: if len(seq)
        if not len(seq)
    

    [..]

    不要使用==将布尔值与True或False进行比较。

    Yes: if greeting:
    No: if greeting == True:
    Worse: if greeting is True:
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看