Python – Find Smallest Number in a Set
To find the smallest number in a Set in Python, you can use Python min() built-in function. min() built-in function takes the set as argument and returns the smallest number in the set.
The syntax of the function call to min(), to find the smallest number in the set s
is
min(s)
ADVERTISEMENT
Example
In the following program, we initialize a Python Set aSet
with numbers and find the smallest of the numbers in the set using min() function.
Program
# initialize set aSet = {2, 1, 7, 6, 5} # find the smallest number smallest = min(aSet) print(f'smallest number : {smallest}')Try Online
Output
smallest number : 1
References
Conclusion
In this Python Tutorial, we learned how to find the smallest number in a set, with the help of example programs.