前言:

‌本文將會介紹介紹布爾值類型及其應用場景。

大綱

  • 布爾值類型
  • int類型的子類
  • 應用

一. 布爾值類型

布爾值(Bool)總共分為兩種類型,兩者均大寫開頭,並非字符串:

  1. True (真)
  2. False (假)
  • Python 認訂為 False 的值:
  • False
  • 0
  • None
  • ‘ ‘
  • [ ], ( ), { }

除了上述所列,其餘都是 True。

二. int 類型的子類

布爾值為int類型的子類,意指其具有數值的性質:

  1. True = 1
  2. False = 0

※ KEY ??非零(False)即真(True)

https://gist.github.com/Celia-code/182a2960ef9b5ea1005aae8cfbfe6bc7

三.應用

1.比較表達式的運算結果

https://gist.github.com/Celia-code/34eff3e7c61f2691e9d109590a790f74

2.if 判斷條件

https://gist.github.com/Celia-code/9380c7a34b0fa6797f06f919333d08ce

查看更多關於 if 判斷條件的介紹 ?? if條件語句教學

3.while循環

https://gist.github.com/Celia-code/761cee39ba9743d4f378fa19e53d9eba

看更多關於 while循環的介紹 ?? Python循環語句 : While循環Python循環語句打斷 : Break&Continue命令

celia

celia

人生苦短,我用Python !

Leave a Reply