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 :: unpack too many values in python 
Python :: length of pandas dataframe 
Python :: how to import file from another directory in python 
Python :: registration of path in urls.py for your apps for views 
Python :: matplotlib custom legend 
Python :: time addition in python 
Python :: how to find 1 st digit in python 
Python :: pandas convert entries in a column after groupby in list 
Python :: convert price to float python 
Python :: python extend list 
Python :: python test if string begins with python 
Python :: Create list with numbers between 2 values 
Python :: python check if character is letter 
Python :: odoo scaffold 
Python :: select non nan values python 
Python :: isnull().mean() python 
Python :: formatting in python 
Python :: python file open 
Python :: Python Excel merge cell 
Python :: python remove punctuation 
Python :: train split 
Python :: standardise columns python 
Python :: list files python 
Python :: scroll down selenium python 
Python :: day name in python 
Python :: python Decompress gzip File 
Python :: python vs c++ 
Python :: list to dataframe 
Python :: how to take input in python3 separated by space 
Python :: how to delete a variable python 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =