python else if 写法
时间: 2023-10-26 09:05:41 浏览: 159
Python中那些 Pythonic的写法详解
在Python中,else if语句可以用elif关键字来表示。
例如:
```
x = 10
if x > 10:
print("x is greater than 10")
elif x < 10:
print("x is less than 10")
else:
print("x is equal to 10")
```
在上面的代码中,如果x大于10,则打印“x is greater than 10”,如果x小于10,则打印“x is less than 10”,否则打印“x is equal to 10”。
阅读全文