Python set max method

Python set max function is one of the set method used to find the maximum value within the given set. In this section, we discuss how to use this Python max set function with practical examples.

The syntax behind this max function is:


Python set max Example 1

The set max function helps you to find the maximum items from the total number of items in a given set. The below code returns the item with the highest Numeric Value from a maximumSet.

TIP: Please refer to the Python set article to understand everything about Sets.

# Python Set max method

maximumSet = {15, 25, 35, 45, 55}
print("\nSet Items = ", maximumSet)

# Python Set Maximum
print("Maximum Value in a Set = ", max(maximumSet))
Python set max method 1

This is another example of the set max function.

# Python Set max method

maximumFruitSet = {'mango', 'kiwi', 'apple', 'orange', 'banana'}
print("\nSet Items = ", maximumFruitSet)

# Python Set Maximum
print("Maximum Value in a Set = ", max(maximumFruitSet))

Set Items =  {'banana', 'mango', 'kiwi', 'orange', 'apple'}
Maximum Value in a Set =  orange