遇到数字元素 为什么会返回None
L=['good','boy','bye',28,'thanks','no','yes',55]
def mys(x):
if isinstance(x,str):
return x.upper()
print [mys(i) for i in L]
运行成功,输出错误
['GOOD', 'BOY', 'BYE', None, 'THANKS', 'NO', 'YES', None]
下面这样写就不会出现None
L=['good','boy','bye',28,'thanks','no','yes',55]
def mys(x):
return x.upper()
print [mys(i) for i in L if isinstance(i,str)]