Using Python's min() and max() (Summary)
Now you know how to use Python’s built-in min()
and max()
functions to find the smallest and largest values in an iterable or in a series of two or more regular arguments. You also learned about a few other characteristics of min()
and max()
that can make them useful in your day-to-day programming.
In this video course, you learned how to:
- Find the smallest and largest values using Python’s
min()
andmax()
, respectively - Call
min()
andmax()
with a single iterable and with several regular arguments - Use
min()
andmax()
with strings and dictionaries - Customize the behavior of
min()
andmax()
withkey
anddefault
- Feed comprehensions and generator expressions into
min()
andmax()
Additionally, you’ve coded a handful of practical examples using min()
and max()
to approach real-world problems that you might run into while coding. You’ve also a written custom version of min()
and max()
in pure Python, a nice learning exercise that helped you understand the logic behind these built-in functions.
Check out these resources to continue your learning:
- 📰 Working With the Python
operator
Module - 📰 Using the Python
zip()
Function for Parallel Iteration - 🎬 Parallel Iteration With Python’s zip() Function
- 📰 Using the
len()
Function in Python - 🎬 Python’s len() Function
- 📰 When to Use a List Comprehension in Python
- 🎬 Understanding Python List Comprehensions
- 📰 Python args and kwargs: Demystified
- 🎬 Python args and kwargs: Demystified
- 📰 Using Python Optional Arguments When Defining Functions
- 🎬 Defining Python Functions With Optional Arguments
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
00:00
Well done. You’ve made it to the end of the course. You now know how to use Python’s built-in min()
and max()
functions to find the smallest and largest values in an iterable or in a series of two or more regular arguments.
00:12
You also learned about a few other characteristics of min()
and max()
that can make them more useful in your day-to-day programming. In this course, you learned how to find the smallest and largest values using Python’s min()
and max()
, call min()
and max()
with a single iterable and with several regular arguments, use min()
and max()
with strings and dictionaries, customize the behavior of min()
and max()
with key
and default
, feed comprehensions and generator expressions into min()
and max()
, code some practical examples using min()
and max()
, and write a custom version of min()
and max()
in pure Python. While on the face of it, min()
and max()
are simple, they are useful in everyday programming, and understanding how to tailor their behavior will make them even more so. Implementing your own version of them is a good programming exercise and provides a basis to create more complex general-purpose functions in the future. We hope you found this course useful, and we’ll see you again soon at realpython.com.
Become a Member to join the conversation.