#coding=utf-8 from enum import Enum #定义自己的枚举时需要使用class,继承Enum类 class Color(Enum): red=1 green=2 blue=3 print Color['red']#Color.red print Color(1)#Color.red #获取成员的name和value print Color.red.name #red print Color.red.value #1 print type(Color.red.name)#<type 'str'> print type(Color.red.value)#<type 'int'> for i in Color: print i ''' Color.red Color.green Color.blue '''
seq = ['one', 'two', 'three']
for i,m in enumerate(seq):
print i,m
for i in enumerate(seq):
print i
'''
0 one
1 two
2 three
(0, 'one')
(1, 'two')
(2, 'three')
'''