Python 3 - Number max() Method


Advertisements

Description

The max() method returns the largest of its arguments i.e. the value closest to positive infinity.

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 the largest of its arguments.

Example

The following example shows the usage of the max() method.

#!/usr/bin/python3

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))

Output

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
python_numbers.htm
Advertisements