Skip to content

Commit 869ccd6

Browse files
committed
docs: add a more precise example
Previous example used manual integer value assignment in class based declaration but in functional syntax has been used auto value assignment what could be confusing for the new users. Additionally documentation doesn't show how to declare new enum via functional syntax with usage of the manual value assignment.
1 parent a905721 commit 869ccd6

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

Doc/library/enum.rst

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,17 @@ An enumeration:
3535
Enumerations are created either by using :keyword:`class` syntax, or by
3636
using function-call syntax::
3737

38-
>>> from enum import Enum
39-
40-
>>> # class syntax
41-
>>> class Color(Enum):
42-
... RED = 1
43-
... GREEN = 2
44-
... BLUE = 3
45-
46-
>>> # functional syntax
47-
>>> Color = Enum('Color', ['RED', 'GREEN', 'BLUE'])
38+
from enum import Enum
39+
40+
41+
class Color(Enum):
42+
RED = '#FF0000'
43+
GREEN = 65280
44+
BLUE = '#0000FF'
45+
46+
47+
# functional syntax
48+
Color = Enum('Color', [('RED', '#FF0000'), ('GREEN', 65280), ('BLUE', '#0000FF')])
4849

4950
Even though we can use :keyword:`class` syntax to create Enums, Enums
5051
are not normal Python classes. See

0 commit comments

Comments
 (0)