python else if 怎么表示
发布网友
发布时间:2022-04-26 06:01
我来回答
共4个回答
热心网友
时间:2022-04-07 13:17
Python中用于多个选择, else if 用 elif表示。
例如:
>>> x = 3
>>> if x<1:
print " x is less than 1. "
elif x<5:
print " x is less than 5. "
elif x<7:
print " x is less than 7. "
else:
print "x is not less than 7. "
该 if 语句从上往下判断,在第二个判断上是True, 则执行其对应的语句。 打印出x is less than 5. 之后就忽略掉剩下 elif 和 else.
热心网友
时间:2022-04-07 14:35
s = ['a', 'b', 'c', 'd']
s[s.index('c')] = 'chinese'
print s
print 'd' * 80
for index, value in enumerate(s):
if 'd' in value:
s[index] = 'Japan'
elif 'b' in value:
s[index] = 'China'
else:
pass
print s
热心网友
时间:2022-04-07 16:09
if something:
pass
elif something:
pass
elif something:
pass
else:
pass
热心网友
时间:2022-04-07 18:01
Python三种配置的写法都不一样,你要哪个