[Python] if 文


if文

注意点
・条件式の後に :
・else if は elif
・条件式左右等しい時は ==

if money > total_price:
    print("りんごを" + str(count) + "個買いました")
    print("残金は" + str(money - total_price) + "円です")
elif money == total_price:
    print("りんごを" + str(count) + "個買いました")
    print("財布は空になりました")
else:
    print("お金が足りません")
    print("りんごを買えませんでした")

条件式組み合わせ

and
どちらの条件も満たす

if time > 10 and time < 15:

or
どちらか一方の条件を満たす

if time == 10 or time == 15:

not
条件の否定

if not time == 20:

比較演算子

jsと違い左右が等しい時の=の数などが変わる。