為什么輸出結果不對 有能解釋的大能么
def toUppers(L):
? ? for x in L:
? ? ? ? if isinstance(x,str):
? ? ? ? ? ? return [x.upper()] ? ?
print toUppers(['Hello', 'world', 101])
def toUppers(L):
? ? for x in L:
? ? ? ? if isinstance(x,str):
? ? ? ? ? ? return [x.upper()] ? ?
print toUppers(['Hello', 'world', 101])
2019-07-20
舉報
2019-09-17
可以這樣改
2019-07-20
return 會直接結束你的循環,跳出這個函數,所以只會輸出HELLO,不會查找list中的第二個字符串,所以輸出結果會出問題