ListView
输入union后,它还会运行else函数。为什么?
答案 0 :(得分:2)
您错过了elif
:
if beer == "union":
print("this is water")
elif beer == "jelen":
print("great")
else:
print("aren't you drinking?")
否则你的两个if
会被单独解释:
# first condition
if beer == "union":
print("this is water")
# end first condition
# second condition
if beer == "jelen": # beer is 'union', this branch doesn't run
print("great")
else: # beer is not 'jelen', so this branch runs
print("aren't you drinking ? ")
# end second condition