廖雪峰Python列表生成式

L1 = [‘Hello’, ‘World’, 18, ‘Apple’, None]
现在把L1里的str改为小写:
①如果删除非str内容:[ x.lower() for x in L1]
②如果不想改变L1内容:[x.lower if isinstance(x,str) else x for x in L1]

对第二句,断句理解应该是这样的:x.lower if isinstance(x,str) else x for x in L1

猜你喜欢

转载自blog.csdn.net/zhuazengbian9095/article/details/82823480