def func(l):
if not isinstance(l,list) or not isinstance(l,tuple):
print ('error')
return None
elif isinstance(l,list):
sum = 0
for item in l:
if isinstance(item,int) or isinstance(item,float):
sum += item
return sum
elif isinstance(l,tuple):
sum = 1
for item in l:
if isinstance(item,int) or isinstance(item,float):
sum = sum * item
return sum
return None
not isinstance(L,list) or not isinstance(L,tuple)
这个条件相当于L既是list也是tuple才是false,实际上L只能是list,或者只能是tuple,所以条件就永远都是true
可以试试改成not isinstance(L,list) and not isinstance(L,tuple),或者not (isinstance(L,list) or isinstance(L,tuple))