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