python enum
Python hosting: Host, run, and code Python in the cloud!
An enum (enumeration) is a set of symbolic names bound to unique constant values.
We can use enums by referring to their names, as opposed to an index number. The constant value can be any type: numeric or text. As the example below:
|
Related course
Module enum installation
To use enums module, you need Python 3.4; To install for Python 3.4:
|
For older versions (Python 2.7):
|
enum example (using enum/aenum)
We can create an Enum after importing the class Enum from either the module enum or aenum.
After importing the list
|
or as a one liner:
|
enum example (without using modules)
The old way of creating enums is:
|
Posted in beginner
Leave a Reply: