Discuss / Python / 详解

详解

Topic source

ynxiu

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

L1 = ['Hello', 'World', 18, 'Apple', None]

L2 = [s.lower() for s in L1 if isinstance(s, str)]

L2为最终结果的 列表解析表达式 s.lower() 最终需要生成的结果并转化成小写 for s in L1 数据来源 if isinstance(s, str) 判断,如果条件成立,才写入本列表,如果不成立就pass掉

所以最终 L2的结果为 ['hello', 'world', 'apple']


  • 1

Reply