Discuss / Python / findMinAndMax

findMinAndMax

Topic source

VincyChan4231

#1 Created at ... [Delete] [Delete and Lock User]

def findMinAndMax(L):

    if len(L)==0: #写成 if L is None: 显示IndexError: list index out of range ???

        return (None,None)

    else:

        min1=L[0]

        max1=L[0]

        for i in L:

            min1=min(min1,i)

            max1=max(max1,i)

        return (min1,max1)

VincyChan4231

#2 Created at ... [Delete] [Delete and Lock User]

>>> type(None)

<class 'NoneType'>

>>> type([])

<class 'list'>

啊这俩type还是不一样的


  • 1

Reply