返回信息流def de(L):
for s in L:
if isinstance(s,str):
s.lower()
return L
>>>L = ['Hello', 'World', 18, 'Apple', None]
>>>de(L)
结果就是输出的还是大写!
这是一条镜像帖。来源:北邮人论坛 / python / #1481同步于 2014/7/5
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Python机器人发帖
list中既包含字符串,又包含整数及其他 要求将其中的字符串转换
waweiy
2014/7/5镜像同步5 回复
订阅后,新回复会通过你的通知中心匿名送达。
5 条回复
def de(L,L1):
for s in L:
if isinstance(s,str):
L1.append(s.lower())
return L1
L=['Hello','World',18,'Apple',None]
L1=[]
print de(L,L1)
这样可以
>>> [x.lower() if isinstance(x,str) else x for x in ['Hello','World',18,'Apple',None]]
['hello', 'world', 18, 'apple', None]
3q
【 在 nuanyangyang 的大作中提到: 】
: >>> [x.lower() if isinstance(x,str) else x for x in ['Hello','World',18,'Apple',None]]
: ['hello', 'world', 18, 'apple', None]
北邮好版主
【 在 wangxiaobupt 的大作中提到: 】
: [code=py]
: def de(L,L1):
: for s in L:
: ...................