【发布时间】:2020-05-14 13:12:30
【问题描述】:
在 python 中,多个“elif”语句的顺序是否重要,特别是在字符串检查中
例如:
if 'foo' in line:
#do something
elif 'bar' in line:
#do other thing
elif 'coffe' in line:
#do other other thing
...
else:
#something something
【问题讨论】:
-
是的。如果一个 elif 为 True,则后续的将无关紧要。
标签: python if-statement