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 :: play video in python console 
Python :: how to change int to four decimal places in python 
Python :: beautifulsoup find 
Python :: how to make a terminal in python 
Python :: how to check for empty dataframe 
Python :: python defaultdict to dict 
Python :: python open google 
Python :: Write a table to CSV file python 
Python :: python get github file content 
Python :: write pyspark dataframe to csv 
Python :: import stock data from yahoo finance 
Python :: python turtle fill 
Python :: python verificar se é numero 
Python :: Format UTC to local timezone using PYTZ for Django 
Python :: how to get first element of array in python 
Python :: how to swap two variables without using third variable python 
Python :: logical operators pandas 
Python :: inherit init method 
Python :: Python - How To Check if a String Contains Word 
Python :: remove column by index 
Python :: continue statement python 
Python :: regex for repeating words python 
Python :: python funtion 
Python :: python how to make a movement controler 
Python :: virtualenv 
Python :: find a key in a dictionary python 
Python :: dropna pandas 
Python :: python pretty print list of tuples 
Python :: python community 
Python :: Using a list with index and column names to Convert List to Dataframe 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =