問題一覧に戻る
初級基本
問題7: 論理演算子

論理演算子は複数の条件を組み合わせたり、条件を反転させたりするために使います。and(かつ)は両方の条件が真の時にTrue、or(または)はどちらか一方が真ならTrue、not(否定)は真偽値を反転させます。条件式を組み合わせて複雑な判定が可能になります。

# 両方の条件を満たすか確認
age = 25
has_license = True
can_drive = age >= 18 has_license
print(can_drive)

# どちらかの条件を満たすか確認
is_weekend = False
is_holiday = True
can_relax = is_weekend is_holiday
print(can_relax)

# 条件を反転
is_raining = True
go_outside = is_raining
print(go_outside)