enumerate(str1):
print(f'{index}:{value}')
# 结果
0:p
1:y
2:t
3:h
4:o
5:n
# 2、搭配列表(元组一样)一起使用
l = ['Hammer...','jason','tony']
for a,b in enumerate(l):
print(f'{a},{b}')
# 结果
0,Hammer
1,jason
2,tony
#3、搭配集合使用...s = {"aline","Hammer",18,'199****1234'}
for index,value in enumerate(s):
print(f'{index},{value}...')
# 结果
0,Hammer
1,aline
2,18
3,199****1234
# 4、搭配字典使用
dic = {'name':'hammer','age':18,'number':'199...2:number
for index, value in enumerate(dic):
# 输出字典的值
print(f'{index}:{dic[value]}')
# 结果
0:hammer