poython中求列表的最大值、最小值、求和和平均值
1、
>>> a = [20,10,50,40,30]
>>> max = a[0]
>>> for i in a:
if i > max:
max = i
>>> print(max)
50
>>> min = a[0]
>>> for i in a:
if i < min:
min = i
>>> print(min)
10
>>> sum = 0
>>> for i in a:
sum += i
>>> print(sum)
150
>>>
>>> print(sum/len(a))
30.0
del max
del min
2、
>>> a = [20,50,30,10,60,40]
>>> max(a) ##最大值
60
>>> min(a) ## 最小值
10
>>> sum(a) ## 求和
210
>>> sum(a)/len(a) ## 求平均值
35.0