How to find the highest number of a list in Python (manually and automatically)

Posted on: January 24th, 2023
By: Tadeo Martinez

Automatically

Python has a built-in function max() which makes it super easy

list = [3,8,2,9]
max_number = max(list)
print (max_number) # it will print 9 as big number

Manually

There will be occasions when you want to do it manually, and it’s also good to know how it works under the hood.

list = [3,8,2,15,9,12]

current_max_number = list[0]
for number in list:
    if number>current_max_number:
        current_max_number = number

print (current_max_number) #it will display 15 as big number

Have any questions or comments? Write them below!


Leave a Reply

Your email address will not be published. Required fields are marked *