以下代碼有什么問題??
def toUppers(L):
? ? return [x.upper() for x in range(0,len(L)) if? isinstance(x,str)]
print toUppers(['Hello', 'world', 101])
def toUppers(L):
? ? return [x.upper() for x in range(0,len(L)) if? isinstance(x,str)]
print toUppers(['Hello', 'world', 101])
2018-08-17
舉報
2018-08-18
range(0,len(L))出來的是L的長度,
for x in range(0,len(L))遍歷出來的是數值
if? isinstance(x,str)] 該if條件判斷僅有字符串才能返回,故上述遍歷全都被判定為不合格,無返回值