Discuss / Python / 试试试试效果还可以

试试试试效果还可以

Topic source

爷左_Cola

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

这个是会剔除数字的

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)

  • 1

Reply