ブール値 ― 論理型

Python のデータ型

Jason Myers

Instructor

データ型としてのブール値

  • True
  • False

Python と他言語を切り替える際は大文字小文字に注意。

out_of_cookies = True
if out_of_cookies:
    print("Run to the store NOW!")
Run to the store NOW!
Python のデータ型

Truthy と Falsey

  • Truthy は true と評価される値
  • Falsey は false と評価される値
apples=2
if apples:
     print("We have apples.")
"We have apples."
apples=0
if apple:
     print('We have apples.')
Python のデータ型

Truthy と Falsey

Truthy

  • 1
  • "Cookies"
  • ["Cake", "Pie"]
  • {"key": "value"}

Falsey

  • 0
  • ""
  • []
  • {}
  • None
Python のデータ型

演算子 ― 真偽評価の文脈

cookie_qty == 3
  • == 等しい
  • != 等しくない
  • < より小さい
  • <= 以下
  • > より大きい
  • >= 以上
Python のデータ型

浮動小数は概ね“問題”です

x = 0.1 + 1.1
x == 1.2
False
print(x)
1.2000000000000002

浮動小数の等価比較には注意!

Python のデータ型

Passons à la pratique !

Python のデータ型

Preparing Video For Download...