Python min() Function



Python function min() returns the smallest of its arguments i.e. the value closest to negative infinity, or smallest number from the iterable (list or tuple)

Syntax

Following is the syntax for the min() function −

min( x, y, z, .... )
min([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 smallest of its arguments.

Example

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

x = -45
y = 90
z = 55
smallest = min(x,y,z)
print ("x: ",x,"y:",y, "z:",z, "min(x,y,z): ", smallest)

x=[45, 90, 55]

smallest = min(x)
print ("x: ",x,"min(x): ", smallest)

x = 4+5j
y = 1+2j
z = 5-4j
smallest = min(x,y,z)
print ("x: ",x,"y:",y, "z:",z, "min(x,y,z): ", smallest)

When we run the above program, it produces the following output

x:  -45 y: 90 z: 55 min(x,y,z):  -45
x:  [45, 90, 55] min(x):  45
Traceback (most recent call last):
  File "/home/cg/root/64a3d0ad4c0e6/main.py", line 12, in <module>
    smallest = min(x,y,z)
               ^^^^^^^^^^
TypeError: '<' not supported between instances of 'complex' and 'complex'
python_built_in_functions.htm
Advertisements