1、求最大值和最小值
>>> test1 = [34,2,5,65,322,21,54] >>> temp = test1[0] >>> for i in test1: if i > temp: temp=i >>> temp 322
>>> for i in test1: if i < temp: temp=i >>> temp 2
2、统计元素次数
>>> test1 = ["a","e","a","b","e","a","b","e"] >>> temp=test1[0] >>> temp 'a'
>>> test2=[] >>> for i in test1: if temp == i: test2.append(i) >>> len(test2) 3