How to find the maximum number in a list using a loop?

Usually, you could just use

max(nums)

If you explicitly want to use a loop, try:

max_value = None
for n in nums:
    if max_value is None or n > max_value: max_value = n

Leave a Comment