關于條件過濾的理解
def toUppers(L):
? ?return [x.upper() for x in L if isinstance(x, str)]
print toUppers(['Hello', 'world', 101])
return [x.upper() for x in L if isinstance(x, str)] ?這句話是什么意思哎 ?怎么去理解?
def toUppers(L):
? ?return [x.upper() for x in L if isinstance(x, str)]
print toUppers(['Hello', 'world', 101])
return [x.upper() for x in L if isinstance(x, str)] ?這句話是什么意思哎 ?怎么去理解?
2017-04-09
舉報
2017-04-10
遍歷L中的元素x,如果x屬于字符串,就變成大寫