tags:

views:

113

answers:

3

I'm wondering if there is any easy way or function to determine the greatest number in a set of numbers. I could just code it, as I only have three numbers, however it would make the code a lot less redundant if I could tell the greatest with a built in function or something.

+10  A: 

What about max()

foo = [1,2,3]
print max(foo)
jskaggz
Thanks, that was exactly what I needed :D
Stealth-
Awesome, have fun python-ing :-)
jskaggz
+2  A: 

Use max()

>>> l = [1, 2, 5]
>>> max(l)
5
>>> 
Chetan
+5  A: 

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.

cletus