1.for … in 循环
循环,遍历,迭代 都是指把容器中的数据一个一个获取出来
lst = [1,2,3,4,5]
i = 0
while i<len(lst):
print(lst[i])
i...for i in container:
print(i)
3.遍历列表
''' Python学习交流,免费公开课,免费资料, 免费答疑,系统学习加QQ群:579817333 '''
container...,b = {"a","b"} 集合有局限性,因为无序;
a,b ={
"a":1,"b":2}
print(a,b)
8.遍历等长的二级容器
''' Python学习交流,免费公开课,免费资料,...range(1,10):
for j in range(1,i+1):
print("%d*%d=%2d " % (i,j,i*j) ,end = "")
print()
总结:
while 一般用于复杂的逻辑操作...for 一般用于数据的遍历
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/170074.html原文链接:https://javaforall.cn