python循环打印问题

对一个列表循环打印,把所有的str类型的转为小写,可以用lower(),但是当有数字时会有问题:
用isinstance()进行判断,然后遍历:
def test(x):
for i in x:
if isinstance(i,str):
print(i.lower())
else:
print(i)
test([‘Hello’,’World’,12])

猜你喜欢

转载自blog.csdn.net/lzl1101206656/article/details/79653263