Get Type Of Enum Variable Python

[Solved] Get Type Of Enum Variable Python | Scala - Code Explorer | yomemimo.com
Question : get type of enum variable python

Answered by :

# Python code to demonstrate enumerations
 
# importing enum for enumerations
import enum
 
# creating enumerations using class
class Animal(enum.Enum):
    dog = auto()
    cat = auto()
    lion = auto()
 
# printing enum member as string
print ("The string representation of enum member is : ",end="")
print (Animal.dog)
 
# printing enum member as repr
print ("The repr representation of enum member is : ",end="")
print (repr(Animal.dog))
 
# printing the type of enum member using type()
print ("The type of enum member is : ",end ="")
print (type(Animal.dog))
 
# printing name of enum member using "name" keyword
print ("The name of enum member is : ",end ="")
print (Animal.dog.name)

Source : https://www.geeksforgeeks.org/enum-in-python/ | Last Update : Mon, 23 May 22

Answers related to get type of enum variable python

Code Explorer Popular Question For Scala