字符串、列表、元组、字典遍历
字符串:
str=“hello world”
for i in str:
print(i,end=" ")
列表:
list=[1,2,3,4,5]
for i in list:
print(i,end=" ")
元组:
tuple=(1,2,3,4,5)
for i in tuple:
print(i,end=" ")
字典:
dict={"name":"张三","age":18}
for i in dict.items():
print(i)
带下标索引的遍历:
char=["a","b","c"]
for i,chr in enumerate(char):
print(i,chr)