Multiple if VS if elif else
786 ワード
if if..(multiple if)
前のif文がtrueの場合、次のifに移動します.
if elif else
前のif文がtrueの場合、終了i = 10
if (i == 10):
# First if statement
if (i < 15):
print("i is smaller than 15")
# Nested - if statement
# Will only be executed if statement above
# it is true
if (i < 12):
print("i is smaller than 12 too")
else:
print("i is greater than 15")
# i is smaller than 15
# i is smaller than 12 too
x = 100
if x > 10:
print("Yes, x > 10")
elif x > 20:
print("Yes, x > 20")
else:
print("not greater than 10")
# Yes, x > 10
Reference
この問題について(Multiple if VS if elif else), 我々は、より多くの情報をここで見つけました
https://velog.io/@yunaaa/Multiple-if-VS-if-elif-else
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
i = 10
if (i == 10):
# First if statement
if (i < 15):
print("i is smaller than 15")
# Nested - if statement
# Will only be executed if statement above
# it is true
if (i < 12):
print("i is smaller than 12 too")
else:
print("i is greater than 15")
# i is smaller than 15
# i is smaller than 12 too
x = 100
if x > 10:
print("Yes, x > 10")
elif x > 20:
print("Yes, x > 20")
else:
print("not greater than 10")
# Yes, x > 10
Reference
この問題について(Multiple if VS if elif else), 我々は、より多くの情報をここで見つけました https://velog.io/@yunaaa/Multiple-if-VS-if-elif-elseテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol