Join Regular Classroom : Visit ClassroomTech

min() function in Python List

It is an inbuilt function in python that returns the min value among all the numbers, if string is involved it returns the alphabetical character with the lowest ascii value.

Syntax:

min(list_name)

Don’t know what is max function in Python List? Read: max() function in Python List

Example 1:

# Python program to understand min() function in list
# www.codewindow.in

s = [85, 55, 47, 98, 32, 65, 62, 54] 
x = min(s)
print(x)

Output:

32

Explanation:

Here the lowest number in the list is 32. Hence it returned 32.

Example 2:

# Python program to understand min() function in list
# www.codewindow.in

s = ["a", "k", "z", "h"] 
x = min(s)
print(x)

Output:

a

Explanation:

Here the ascii value of “a” is the lowest among all other characters. Hence it returned “a”.

Example 3:

# Python program to understand min() function in list
# www.codewindow.in

s = ["code", "and", "hustle"]
x = min(s)
print(x)

Output:

and

Explanation:

Here the ascii value of “a” in “and” is the lowest among all other characters. Hence it returned “and”.


You Missed

Also Checkout