0
0
Pythonprogramming~5 mins

max() and min() in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the max() function do in Python?
The max() function returns the largest item from an iterable or the largest of two or more arguments.
Click to reveal answer
beginner
What does the min() function do in Python?
The min() function returns the smallest item from an iterable or the smallest of two or more arguments.
Click to reveal answer
beginner
How can you find the maximum number in a list [3, 7, 2, 9]?
Use max([3, 7, 2, 9]) which will return 9.
Click to reveal answer
beginner
How can you find the minimum value among numbers 5, 10, and 1?
Use min(5, 10, 1) which will return 1.
Click to reveal answer
intermediate
Can max() and min() be used with strings? How?
Yes! They compare strings alphabetically (based on Unicode). For example, max(['apple', 'banana', 'cherry']) returns 'cherry' because 'c' comes after 'a' and 'b'.
Click to reveal answer
What will max([4, 9, 1, 7]) return?
A4
B7
C9
D1
What does min('dog', 'cat', 'bat') return?
A'bat'
B'cat'
C'dog'
DError
Which of these is a valid way to use max()?
Amax(3, 5, 2)
BAll of the above
Cmax('a', 'z', 'm')
Dmax([3, 5, 2])
What will min([]) do?
ARaise a ValueError
BReturn None
CReturn 0
DReturn an empty list
How does max() decide which item is largest when given strings?
ABy string length
BRandomly
CBy number of vowels
DAlphabetically (Unicode order)
Explain how to use max() and min() with a list of numbers.
Think about finding the highest and lowest scores in a game.
You got /4 concepts.
    Describe what happens if you use max() or min() on strings.
    Think about dictionary order.
    You got /4 concepts.