Discuss / Python / 代码

代码

Topic source
在此插入代码

L1 = ['Hello', 'World', 18, 'Apple', None] L2 = [x.lower() for x in L1 if isinstance(x,str)] print(L2

_假行僧_

#2 Created at ... [Delete] [Delete and Lock User]

好漂亮

这应该是出题人想要的答案

行人Aiya

#4 Created at ... [Delete] [Delete and Lock User]

漂亮

q6065406

#5 Created at ... [Delete] [Delete and Lock User]

为什么输出的结果不是['hello', 'world, 18, 'apple', None]

Mr丶mupa

#6 Created at ... [Delete] [Delete and Lock User]

[s.lower() if isinstance(s,str) else s for s in L]、 我觉得这才是对的吧。。。


  • 1

Reply