问答详情
源自:9-5 Python函数参数

为什么输出区是两个None

def func(listLorLtuple):

    if listLorLtuple is list:

        for l in listLorLtuple:

            return listLorLtuple[0],listLorLtuple[1],listLorLtuple[2],listLorLtuple[3],listLorLtuple[4],listLorLtuple[5],listLorLtuple[6],listLorLtuple[7],listLorLtuple[8],listLorLtuple[9],listLorLtuple[10]

    if listLorLtuple is tuple:

        return listLorLtuple[0]*listLorLtuple[1]*listLorLtuple[2]*listLorLtuple[3]*listLorLtuple[4]*listLorLtuple[5]*listLorLtuple[6]*listLorLtuple[7]*listLorLtuple[8]*listLorLtuple[9]*listLorLtuple[10]

    



L = [1,2,3,4,5,6,7,8,9,10]

T = (1,2,3,4,5,6,7,8,9,10)

print(func(L))

print(func(T))



提问者:Clzypx 2023-07-12 19:40

个回答

  • 慕神1423959
    2023-07-13 11:26:57

    应该用isinstance(listLorLtuple, list):判断类型