Python min() function
Python min() Function
Description
The min() function returns the smallest of its arguments, that is, the value closest to negative infinity, or the smallest number in an iterable (a list or tuple).
Syntax
The 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 minimum of its arguments.
Example
The following example demonstrates the use 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'