función
Python min () con el Ejemplo: En este artículo, vamos a aprender con un ejemplo sobre función min () que es una función incorporada en Python .
Python – min () función
min () es una función incorporada en Python, que puede tomar un número N de argumentos y devuelve el valor mínimo de sus argumentos.
class ejemplo , si proporcionamos 3 argumentos con los valores 20, 10 y 30. min () se class 10, ya que es el valor mínimo entre estos 3 argumentos.
Sintaxis:
min(arg1, arg2, arg3, ...)
Aquí, arg1 , arg2 y arg3 son los argumentos que pueden entero, cadena etc.
Ejemplo:
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.
El código fuente:
#Simple example to get min value
#from given arguments
#this will print 10
print "min(20, 10, 30) : ", min(20, 10, 30)
#this will print ABC
print "min('ABC', 'PQR', 'HELLO') : ", min('ABC', 'PQR', 'HELLO')
salida
min(20, 10, 30) : 10
min('ABC', 'PQR', 'HELLO') : ABC
Encontrar más pequeño alfabeto / mínima de cadena dada
Sí! También se puede utilizar para obtener el alfabeto de valor ASCII mínima de cadena dada.
Sintaxis:
min(string)
En este For, cadena es un argumento. Aquí, min () se return mínima y / o alfabeto más pequeño que tiene bajo valor ASCII.
Código Fuente:
#program to get minimum/smallest
#character from given string
#this will return 'H'
print "min('Hello') : ", min('Hello')
#this will return 'E'
print "min('HELLO') : ", min('HELLO')
#this will return 'e'
print "min('hello') : ", min('hello')
salida
min('Hello') : H
min('HELLO') : E
min('hello') : e