Python中的min及如何返回最小值索引

1、Python的min函数返回列表中的最小的项。

2、如何返回列表中最小的项的索引?

def indexofMin(arr):
    minindex = 0
    currentindex = 1
    while currentindex < len(arr):
        if arr[currentindex] < arr[minindex]:
            minindex = currentindex
        currentindex += 1
    return minindex
arr = [3,5,2,1]
print(indexofMin(arr))

猜你喜欢

转载自blog.csdn.net/su_bao/article/details/81050960