Python使用for循环找到最小值?

Eas*_*ill 1 python loops minimum

我不知道如何让 python 在列表中“扫描”候选者,然后再次返回循环以找到最小值的另一个候选者。

    candidate = 0
    maximum = 0
    a = [12, 10, 50, 100, 24]
    for i in len(s):
        for j in range(len(s)):
Run Code Online (Sandbox Code Playgroud)

the*_*eye 5

您可以使用内置min函数来执行此操作

a = [12, 10, 50, 100, 24]
print min(a)
Run Code Online (Sandbox Code Playgroud)

如果你真的想使用循环,

minimum = a[0]
for number in a:
    if minimum > number:
       minimum = number
print minimum
Run Code Online (Sandbox Code Playgroud)

您可以使用max函数来查找列表中的最大值。