为False的几种情况

  • 0为False,其他所有数值皆为True
  • 空串("")为False,其他所有字符串皆为True
  • 空list([])为False,其他所有list皆为True
  • 空tuple(())为False,其他所有tuple皆为True
  • 空dict({})为False,其他所有dcit皆为True

杜绝的几种写法

if i==0:
if str==“”:
if list == None:
if set is None:
if dict == None:

优雅写法

对应上面的例子

if not i:
if not str:
if not list:
if not set:
if not dicte:
 
 
jihite

为False的几种情况

  • 0为False,其他所有数值皆为True
  • 空串("")为False,其他所有字符串皆为True
  • 空list([])为False,其他所有list皆为True
  • 空tuple(())为False,其他所有tuple皆为True
  • 空dict({})为False,其他所有dcit皆为True

杜绝的几种写法

if i==0:
if str==“”:
if list == None:
if set is None:
if dict == None:

优雅写法

对应上面的例子

if not i:
if not str:
if not list:
if not set:
if not dicte:

相关文章:

  • 2021-08-14
  • 2021-09-03
  • 2021-04-16
  • 2022-12-23
  • 2022-02-03
  • 2021-07-28
  • 2021-09-05
猜你喜欢
  • 2021-09-23
  • 2022-02-03
  • 2022-03-04
  • 2021-07-05
  • 2021-08-09
  • 2021-06-03
  • 2022-12-23
相关资源
相似解决方案