Python Number min() Method


Contents

Description

The min() method in Python number returns the smallest of its arguments i.e. the value which is closest to the negative infinity. The Python min() belongs to the list functions. Furthermore, if min() Python number method is called with an iterable then it possibly returns the smallest of item into it, however, if the iterable is empty then it would return a default value preassuming it to be provided, otherwise, it would raise a ValueError exception. Moreover, if the min() method in Python number is called over with multiple arguments then it would return the minimum value within a list.

Syntax

Following is the syntax for min() method −

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

Example

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

#!/usr/bin/python

print "min(80, 100, 1000) : ", min(80, 100, 1000)
print "min(-20, 100, 400) : ", min(-20, 100, 400)
print "min(-80, -20, -10) : ", min(-80, -20, -10)
print "min(0, 100, -400) : ", min(0, 100, -400)

When we run above program, it produces following result:

min(80, 100, 1000) :  80
min(-20, 100, 400) :  -20
min(-80, -20, -10) :  -80
min(0, 100, -400) :  -400

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.



Navigation
Tutorial
Tutorial
Tutorial