logo

Python Number Max() Method


Show

Description

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.

Syntax

Following is the syntax for max() method:

max( x, y, z, .... )

Parameters

  • x - This is a numeric expression.
  • y - This is also a numeric expression.
  • z - This is also a numeric expression.

Return Value

This method returns largest of its arguments.

Example

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.