The max() method in Python number returns the largest of its arguments i.e. the value closest to positive infinity. This method can be used for finding out the largest item amongst two or more parameters. It is known for returning the highest value and in case of an iterable for returning the item with the highest value. In case the values stand out to be string then an alphabetical comparison is made.
Following is the syntax for max() method:
max( x, y, z, .... )
This method returns largest of its arguments.
The following example shows the usage of max() method.
#!/usr/bin/python print "max(80, 100, 1000) : ", max(80, 100, 1000) print "max(-20, 100, 400) : ", max(-20, 100, 400) print "max(-80, -20, -10) : ", max(-80, -20, -10) print "max(0, 100, -400) : ", max(0, 100, -400)
When we run the above program, it produces the following result:
max(80, 100, 1000) : 1000 max(-20, 100, 400) : 400 max(-80, -20, -10) : -10 max(0, 100, -400) : 100
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.