Python Set – min() Function

It is a function in python that returns the element with the minimum value in the given set. If it’s a string then it returns the value with the lowest ASCII value.
It doesn’t modifies the given set.

Syntax:
min(set)

Also Read:Python Set – max() Function

Example 1:

# Python code to understand min() Function in set
# www.codewindow.in

s1 = {"zebra", "window"}
s = {"code", "website", "best"}
print(min(s1))
print(min(s))

Output:

window
best

Explanation:
Here, it returned “window” as “w” having the lowest ASCII value among all other values. The next one “best” as “b” having the lowest ascii value among all other values.

Example 2:

# Python code to understand min() Function in set
# www.codewindow.in

s1 = {2, 5, 8, 7, 9}
s = {10, 5, 1}
print(min(s1))
print(min(s))

Output:

2
1

Explanation:
Here, 2 is the minimum value among all the other elements in set s1 and 1 is the minimum value among all the other elements in set s.


Follow Us

You Missed

Also Checkout