Find the greatest number in a list of numbers Find the greatest number in a list of numbers python python

Find the greatest number in a list of numbers


What about max()

highest = max(1, 2, 3)  # or max([1, 2, 3]) for lists


You can use the inbuilt function max() with multiple arguments:

print max(1, 2, 3)

or a list:

list = [1, 2, 3]print max(list)

or in fact anything iterable.


This approach is without using max() function

a = [1,2,3,4,6,7,99,88,999]max_num = 0for i in a:    if i > max_num:        max_num = iprint(max_num)

Also if you want to find the index of the resulting max,

print(a.index(max_num))

Direct approach by using function max()

max() function returns the item with the highest value, or the item with the highest value in an iterable

Example: when you have to find max on integers/numbers

a = (1, 5, 3, 9)print(max(a))>> 9

Example: when you have string

x = max("Mike", "John", "Vicky")print(x)>> Vicky

It basically returns the name with the highest value, ordered alphabetically.