遇到數字元素 為什么會返回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)]
2019-10-18
2020-01-11