Related Articles
Python | Maximum and Minimum in a Set
• Difficulty Level : Basic
• Last Updated : 28 Dec, 2017

In this article, we will learn how to get the maximum and minimum element in a set in Python, using the built-in functions of Python.
Examples:

```Input : set = ([8, 16, 24, 1, 25, 3, 10, 65, 55])
Output : max is 65

Input : set = ([4, 12, 10, 9, 4, 13])
Output : min is 4
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

max() in a Set

The built-in function max() in Python is used to get the maximum of all the elements in a set.

 `# Python code to get the maximum element from a set ` `def` `MAX``(sets): ` `    ``return` `(``max``(sets)) ` `     `  `# Driver Code ` `sets ``=` `set``([``8``, ``16``, ``24``, ``1``, ``25``, ``3``, ``10``, ``65``, ``55``]) ` `print``(``MAX``(sets)) `

Output:

```65
```

min() in a Set

 `# Python code to get the minimum element from a set ` `def` `MIN``(sets): ` `    ``return` `(``min``(sets)) ` `     `  `# Driver Code ` `sets ``=` `set``([``4``, ``12``, ``10``, ``9``, ``4``, ``13``]) ` `print``(``MIN``(sets)) `

Output:

```4
```

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :