在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