Python找到最小的for循环? [英] Python find the minimum using for loops?
本文介绍了Python找到最小的for循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道如何让python在列表中扫描"一个候选者,然后再次返回循环以找到另一个候选者.
I don't know how to make python "scan" through the list for a candidate and then go back to the loop again to find another candidate for the min.
candidate = 0
maximum = 0
a = [12, 10, 50, 100, 24]
for i in len(s):
for j in range(len(s)):
推荐答案
You can use the builtin min
function to do this
a = [12, 10, 50, 100, 24]
print min(a)
如果您真的想使用循环,
If you really want to use loop,
minimum = a[0]
for number in a:
if minimum > number:
minimum = number
print minimum
您可以使用 max
函数在列表.
You can use max
function to find the maximum in a list.
这篇关于Python找到最小的for循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文