Python Max Function: Usage & Examples

The max function is used to return the maximum value of the given parameters. It can take multiple arguments or a single iterable object as a parameter. For example:

Find the maximum value:

a = 10
b = 20
c = 30

max_num = max(a, b, c)
print(max_num)  # 输出:30

求取列表中的最大值:
Find the maximum value in the list.

my_list = [10, 20, 30, 40, 50]

max_num = max(my_list)
print(max_num)  # 输出:50

Find the maximum value in the dictionary:

my_dict = {'a': 10, 'b': 20, 'c': 30}

max_num = max(my_dict.values())
print(max_num)  # 输出:30
bannerAds