首页 > 代码库 > Python之路-枚举enumerate

Python之路-枚举enumerate

将列表转化成枚举类型示例:
li =[‘电脑‘,‘手机‘,‘电视‘]
for key,item in enumerate(li):
    print(key,item)
i = input("please input index:")
index = int(i)
print(li[index])

Python之路-枚举enumerate