-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenum_type.py
More file actions
49 lines (33 loc) · 737 Bytes
/
enum_type.py
File metadata and controls
49 lines (33 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from enum import Enum
class color(Enum):
red = 1
green = 2
blue = 2
color.red
color.green
mm = color(1)
mm = color(2)
color['red']
mm = color['green']
mm.name
nn.value
@unique
class color(Enum):
red = 1
green = 2
blue = 2
list(color)
for name, member in Shape.__members__.items():
name, member
('square', <Shape.square: 2>)
('diamond', <Shape.diamond: 1>)
('circle', <Shape.circle: 3>)
('alias_for_square', <Shape.square: 2>)
Color.red is Color.red
Color.red is not Color.red
Color.red == Color.red
Note :Subclassing an enumeration is allowed only if the enumeration does not define any members
Animal = Enum('Animal', 'ant bee cat dog')
class Shape(IntEnum):
circle = 1
square = 2