练习
Topic sourceL3=[s.lower() if isinstance(s,str)==True else s for s in L1]
===>
['hello', 'world', 18, 'apple', None]
为什么你这样转一下就可以了?'else s'自动把s转成字符串了?有点不理解
print([name.lower() if isinstance(name, str) else str(name) for name in L])
===>
['hello', 'world', '18', 'apple', 'None']
这样才是转成字符串呀
- 1
無淣
L1=['Hello','World',18,'Apple',None]
L2=[s.lower() for s in L1 if isinstance(s,str)==True]
L3=[s.lower() if isinstance(s,str)==True else s for s in L1]
print(L2)
print(L3)