假如有一个列表按照大小进行排序
#冒泡排序:按顺序排序 li = [33,2,10,1] for j in range(1,len(li)): for i in range(len(li) - j): if li[i] > li[i + 1]: temp = li[i] li[i] = li[i + 1] li[i + 1] = temp print(li) #显示结果 #D:Python35python.exe D:/py_code/set/冒泡算法/冒泡算法.py #[1, 2, 10, 33] #Process finished with exit code 0
range函数用法
#!/usr/bin/env python # -*- coding:utf-8 -*- li = [33,2,10,1] for j in range(5): print(j) print("----------") for i in range(1,5): print(i) """ 显示结果 D:Python35python.exe D:/py_code/set/range函数.py 0 1 2 3 4 ---------- 1 2 3 4 """