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
More Related Contents:
- How do you find min and max without using min and max function [duplicate]
- Accessing the index in ‘for’ loops
- Strange result when removing item from a list while iterating over it
- Modifying list while iterating [duplicate]
- Iterate through pairs of items in a Python list [duplicate]
- Getting the index of the returned max or min item using max()/min() on a list
- Removing Item From List – during iteration – what’s wrong with this idiom?
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- Finding max value in the second column of a nested list?
- Can’t modify list elements in a loop [duplicate]
- How to find all positions of the maximum value in a list?
- Python – TypeError: ‘int’ object is not iterable
- How to iterate over a list in chunks
- Find the item with maximum occurrences in a list [duplicate]
- How do I loop through a list by twos? [duplicate]
- How to find the min/max value of a common key in a list of dicts?
- Assigning values to variables in a list using a loop
- python assign values to list elements in loop
- How to transform string of space-separated key,value pairs of unique words into a dict
- Why do I get “List index out of range” when trying to add consecutive numbers in a list using “for i in list”? [duplicate]
- Why does a for-loop with pop-method (or del statement) not iterate over all list elements [duplicate]
- Why doesn’t assigning to the loop variable modify the original list? How can I assign back to the list in a loop? [duplicate]
- Iterate through adjacent pairs of items in a Python list [duplicate]
- How can I avoid “RuntimeError: dictionary changed size during iteration” error?
- Check if all values in list are greater than a certain number
- Loop over 2 lists, repeating the shortest until end of longest [duplicate]
- Loop through list with both content and index [duplicate]
- How to find the max number(s) in a list with tied numbers
- Count duplicates between 2 lists
- Strange result when removing item from a list while iterating over it in Python