这个是会剔除数字的
L3=[s.lower() for s in L1 if isinstance(s,str)]
这个是会保留数字的
L = ['Hello', 'World', 18, 'Apple', None] L2=[] #[s.lower() if isinstance(s,str) for s in L] for s in L: if isinstance(s,str):# 判断变量是否为字符串的函数 s=s.lower() #将字符串转变为小写的函数 L2.append(s)#插入L2列表的函数 print(L) print(L2)
Sign in to make a reply
爷左_Cola
这个是会剔除数字的
这个是会保留数字的