Python 条件语句
Else
The else keyword catches anything which isn't caught by the preceding conditions.
示例
a = 200
b = 33
if b > a
print("b is greater than a")
elif a == b
print("a and b are equal")
else
print("a is greater than b")
动手试试 »
在这个例子中,a 大于 b,所以第一个条件不成立,elif 条件也不成立,所以我们进入 else 条件,并打印到屏幕上 "a is greater than b".
你也可以在没有 elif
的情况下使用 else