Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python enum

from enum import Enum
class Color(Enum):
    RED = 1
    GREEN = 2     
    BLUE = 3

"""
Color.RED
RED
1
Color.RED
"""
print(Color.RED)
print(Color.RED.name)
print(Color.RED.value)
print(Color["RED"])

val = "RED"
print(f"Value is {Color[val].value}")
Comment

enum python

>>> from enum import Enum
>>> class Color(Enum):
...     RED = 1
...     GREEN = 2
...     BLUE = 3
...
Comment

python using enum module

from enum import Enum

class Day(Enum):
    MONDAY = 1
    TUESDAY = 2
    WEDNESDAY = 3

# print the enum member
print(Day.MONDAY)

# get the name of the enum member
print(Day.MONDAY.name)

# get the value of the enum member
print(Day.MONDAY.value)
Comment

python enum

An enumeration is a set of symbolic names (members) bound to unique, constant values. Within an enumeration, the members can be compared by identity, and the enumeration itself can be iterated over.
Comment

PREVIOUS NEXT
Code Example
Python :: how to make a modulo in python 
Python :: what are for loops 
Python :: commands.has_role discord.py 
Python :: python youtube downloader (Downloading multiple videos) 
Python :: web3.py failing not installing 
Python :: python program to calculate factorial of a number. 
Python :: new line eval python 
Python :: if lower: --- 71 doc = doc.lower() 72 if accent_function is not None: 73 doc = accent_function(doc) 
Python :: convert string input into a nested tuple in python 
Python :: how to count the iteration a list python 
Python :: keras.utils.plot_model keeps telling me to install pydot and graphviz 
Python :: a string varible in python 
Python :: printing a varible with a varible. python 
Python :: pandas get indices of mask 
Python :: HttpResponse Object Error in view.py 
Python :: django query multiple 
Python :: image segmentation pyimagesearch 
Python :: #finding the differences between setA and SetB: 
Python :: write str in a formal way in python 
Python :: Filter xarray 
Python :: add service files in setup.py ROS2 
Python :: python type checking dictionary mypy 
Python :: circular reference detected python repl.it 
Python :: python data engineer interview questions 
Python :: numpy how to apply interpolation all rows 
Python :: discertize dara python 
Python :: torch.nn.Linear(in_features, out_features, bias=True) discription 
Python :: combining sparse class 
Python :: python hash md5 unicode 
Python :: extends template django file system 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =