Python if文

ifの書き方

 age = 10
if age > 10:
print("more than ten.")

 ifの開始がコロン":"なので注意

if-elseの書き方

 age = 10
if age > 10:
print("more than ten.")
else:
print("less than ten.")

 elseの開始もコロン":"なので注意

if-elif-elseの書き方

age = 12
age = 12
if age == 10:
print("you are ten.")
elif age == 11:
print("you are eleven.")
elif age == 12:
print("you are twelve.")
else:
print("you are more than thirteen")

elifの開始もコロン":"なので注意

条件の連結

orで連結

age = 12
if age == 10 or age == 11 or age == 12:
print("you are ten or eleven or twelve.")
else:
print("you are more than thirteen or ...")

andで連結

age = 20
if age >= 10 and age <= 12:
print("you are ten or eleven or twelve.")
else:
print("you are more than thirteen or ...")