第一种方法:通过排序,切片,取倒数第二个值
list1 = [1,2,6,4,5,7] list2 = sorted(list1) list3= list2[-2] print(list3)
第二种方法:循环列表中的值
list1 = [1,2,6,4,5,8,10,12,13,15] one = list1[0] two = list1[1] for i in range(1,len(list1)): if list1[i] > one: two = one one = list1[i] elif list1[i] > two: two = list1[i] else: pass print(two)