Get the maximum and minimum values of a list in python

To obtain the maximum and minimum values ​​of elements in a list in python, the max() and min() methods are usually used.

Among them, the max() method returns the maximum value of the elements in the list, and the min() method returns the minimum value of the elements in the list.

Examples are as follows:

#!/usr/bin/env python
# -*- coding:utf-8 -*-


if __name__ == '__main__':
    test = [12, 32, 28, 38, 29, 2, 56, 78, 39, 98]
    # 输出最大值
    print(max(test))
    # 输出最小值
    print(min(test))

output:

98
2

Guess you like

Origin blog.csdn.net/kevinjin2011/article/details/129733912