if - Python3

if を使った条件分岐

「 score 」が85点以上なら合格の文字が表示されます。

score = 95

if score >= 85:
  print("合格")

if ~ else

elseブロックで、条件式が false の時の処理を追加できます。

score = 75

if score >= 80:
  print("合格")
else:
  print("不合格")

elif

複数の条件を指定するには、Python では 「 elif 」を使います。

item = "lemon"

if item == "apple":
  print("apple:" + str(100))
elif item == "banana":
  print("banana:" + str(50))
elif item == "orange":
  print("orange:" + str(80))
else:
  print("other:" + str(30))

if not

item = "ruby"

if not(item == "python"):
  print("python ではありません")
else:
  print("true")