Python suggest change

Enum

Enums were added to Python in version 3.4 by PEP 435.

Creating an enum

from enum import Enum

class Color(Enum):
    red = 1
    green = 2
    blue = 3

print(Color.red)  # Color.red    
print(Color(1))  # Color.red    
print(Color['red'])  # Color.red

Iterating an enum

class Color(Enum):
    red = 1
    green = 2
    blue = 3

[c for c in Color]  # [<Color.red: 1>, <Color.green: 2>, <Color.blue: 3>]

Enums before 3.4

To use enums in Python less than 3.4, you can use enum34 package:

pip install enum34

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Table Of Contents
32 Set
46 Enum
105 Stack
119 Mixins
121 ArcPy
127 Arrays
139 Neo4j
141 Curses
146 heapq
155 Audio
156 pyglet
158 ijson
161 Flask
164 pygame
167 Gzip
168 ctypes
187 shelve
  ↑ ↓ to navigate     ↵ to select     Esc to close