我们可以elif在列表理解中使用吗?
示例:
l = [1, 2, 3, 4, 5]
for values in l:
if values==1:
print 'yes'
elif values==2:
print 'no'
else:
print 'idle'
Run Code Online (Sandbox Code Playgroud)
我们能否elif以类似于上面代码的方式包含我们的列表理解?
例如,答案如下:
['yes', 'no', 'idle', 'idle', 'idle']
Run Code Online (Sandbox Code Playgroud)
到目前为止,我只使用if和else列表理解.