Select to view content in your preferred language

max function

2532
1
03-06-2012 06:39 AM
RameshGautam
Emerging Contributor
Does Python has 'max' function?

I need to find maximum value among hundreds of variables. For example, I have 2, 3, 4, 1, 2, 3, 4, 5, 1, 2, 3, 0, 10, 20, etc and I would like to write a code like
max(2, 3, 4, 1, 2, 3, 4, 5, 1, 2, 3, 0, 10, 20) and get the maximu value. I tried, somehow it did not work.

I found a max function in ArcGIS help as
max([!field1!, !field2!, !field3!])

what does ! mean?

Thanks
Tags (2)
0 Kudos
1 Reply
curtvprice
MVP Alum
max(2, 3, 4, 1, 2, 3, 4, 5, 1, 2, 3, 0, 10, 20) and get the maximu value. I tried, somehow it did not work.


Yes, it should work. there are two valid syntaxes:

>>> max(3,2,1,5)
5
>>> max([3,2,1,5])
5


I found a max function in ArcGIS help as
max([!field1!, !field2!, !field3!])

what does ! mean?


This is the python max function (second syntax), used inside the Calculate Field tool (which uses a "!" delimeter to substitute field names in to Python expressions).
0 Kudos