min() 是Python中的内置函数,它可以接受N个参数,并返回其参数的最小值。
例如,如果我们提供3个参数,其值分别为20、10和30。min() 将返回10,因为这是这3个参数中的最小值。
语法:
min(arg1, arg2, arg3, ...)
在这里, arg1,arg2和arg3是可以为整数,字符串等的参数。
示例
Input arguments are: 20, 10, 30 Output: 10 Because 10 is the smallest argument here. Input arguments are: “ABC”, “PQR”, “Hello” Output: “ABC” Because “ABC” is the minimum argument according to its length and alphabetically sequences.
源代码:
#获得最小值的简单示例 #从给定的论点 #这将打印10 print "min(20, 10, 30) : ", min(20, 10, 30) #这将打印ABC print "min('ABC', 'PQR', 'HELLO') : ", min('ABC', 'PQR', 'HELLO')
输出结果
min(20, 10, 30) : 10 min('ABC', 'PQR', 'HELLO') : ABC
是! 它也可以用来从给定的字符串中获取最小ASCII值的字母。
语法:
min(string)
在这种情况下,字符串是一个参数。这里,min() 将返回具有最低ASCII值的最小/最小字母。
源代码:
#程序获得最小/最小 #给定字符串中的字符 #这将返回“ H” print "min('Hello') : ", min('Hello') #这将返回“ E” print "min('HELLO') : ", min('HELLO') #这将返回“ E” print "min('hello') : ", min('hello')
输出结果
min('Hello') : H min('HELLO') : E min('hello') : e