其他功能运行,但它不应该

时间:2017-07-20 11:33:47

标签: python-3.x

ListView

输入union后,它还会运行else函数。为什么?

1 个答案:

答案 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