for循环

for循环的使用

1> 在list 或 dictionary 使用
list = [1,2,3,4,5,6]
for i in list: # list
print(i)

for item in dic: # dictionary
print(dic[item])

2> 使用range()函数,该函数返回值为类型为list
range(stop) # 0到stop-1
range(start, stop) #从start到stop-1,默认步长为1
range(start, stop, step) #从start到stop-1,步长为step

for i in range(0,10): #range(0,10) 返回[0,1,2,3,4,5,6,7,8,9]
print(i)

原文地址:https://www.cnblogs.com/jxgapyw/p/5134417.html