#遍历字符串 str = "abc" for value in str : print ( value ) #遍历列表: my_list = [ "苹果" , "草莓" ] for value in my_list : print ( value ) #遍历字典 my_dict = { "name" : "何春桥" , "age" : 6 } #遍历(默认遍历出来
str = "abc"
for value in str:
print(value)
#遍历列表:
my_list = ["苹果","草莓"]
for value in my_list:
print(value)
#遍历字典
my_dict = {"name":"何春桥","age":6}
#遍历(默认遍历出来的是key)
for key in my_dict:
print(key)
#遍历value
for value in my_dict.values():
print(value)
#将key和value全部都遍历出来
for key,value in {"name":"何春桥","age":6}.items():
print(key,value)
#遍历枚举
my_list = enumerate(["苹果","草莓"])
print(type(my_list))
#
for value in my_list:
print(value,type(value))
#拆包:获取枚举类型中所有元素和所有下标
#遍历下标
for index,value in my_list:
print(index,value)