在Python中怎么表达True


为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:


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM