bool型
論理値を扱うために用いられるクラス型のこと。ビルトイン型である。 主な生成方法:
関係演算子や論理演算子の演算結果
直接書き込む
直接書き込む方法
True, Falseという表記は論理値として解釈され、bool型インスタンスとなる。
code:type_bool1.py
x = True
print(x, type(x))
y = False
print(y, type(y))
演算結果
関係演算子の計算結果はbool値で返される。
code:type_bool2.py
x = 1 == 2
print(x, type(x))
y = 1 < 2
print(y, type(y))
and, or, not などの論理演算子が定義されている。 code:type_bool3.py
x = True and True
print(x, type(x))
y = 1 == 2 or 1 > 2
print(y, type(y))
/icons/hr.icon
※ ブラウザのバックボタンで戻る
https://scrapbox.io/files/650d1b37966ef5001b290345.png