在python 判断语句中 None, False, 空字符串"", 0, 空列表[], 空字典{}, 空元组()都相当于 False
not None == not False == not '' == not 0 == not [] == not {} == not ()

 

需要注意的是'0'这个进行判断返回的是true

def test(val):
    if not val:
        print 'not'
    else:
        print 'yes'

test(0)
test(None)

test('0')


if not 0:
    print 1111

返回

not
not
yes
1111

 

相关文章:

  • 2022-12-23
  • 2021-08-14
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2021-07-18
  • 2021-07-01
猜你喜欢
  • 2021-07-28
  • 2021-06-29
  • 2021-08-21
  • 2021-11-16
  • 2021-07-18
  • 2022-02-18
  • 2021-06-08
相关资源
相似解决方案