python知识2:列表、元组、字符串的遍历【多测师】

遍历列表:
list= ['a', 'b', 'c', 'd', 'e’]
list1 = []
for i in range(0, len(list)):
    list1=list[i]

    print(list1)

list= ['a', 'b', 'c', 'd', 'e']
for i in range(0, len(list)):
    print(list[I])

Break 和continue 

list= ['a', 'b', 'c', 'd', 'e','f','g']

for i in range(0, len(list)):
    if list[i]=='d':
        continue

    print(list[I])

list= ['a', 'b', 'c', 'd', 'e','f','g']

for i in range(0, len(list)):
    if list[i]=='d':
        break

    print(list[I])

for i in 后面可以对列表、字符串、元组、字典、文件进行遍历
for i in range(0,1) or(5) or(0,len(list))etc 后面只能接数字或者数字区间
元组的值是不能进行修改的
字典可以通过key值来取的value值

原文地址:https://www.cnblogs.com/xiaoshubass/p/13113893.html