如何使用循环查找列表中的最大数目? [英] How to find the maximum number in a list using a loop?
本文介绍了如何使用循环查找列表中的最大数目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有此列表和变量:
So I have this list and variables:
nums = [14, 8, 9, 16, 3, 11, 5]
big = nums[0]
spot = 0
我对如何实际执行感到困惑.我想用这个练习来给我一个入门.如何在Python上做到这一点?
I'm confused about how to actually do it. I want to use this exercise to give me a starter. How do I do that on Python?
推荐答案
通常,您可以使用
max(nums)
如果您明确想使用循环,请尝试:
If you explicitly want to use a loop, try:
max_value = None
for n in nums:
if n > max_value: max_value = n
这篇关于如何使用循环查找列表中的最大数目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文