Python Class inheriting Enum only vs. both str, Enum
Whats the difference between an enum class that inherits Enum compared with one that inherits str, Enum, and when do you decide to use the one that has both str, Enum? I tried printing out the names and values of both types of enum instances, but they appear similar from enum import Enum class Animals(Enum): CAT = "cat" DOG = "dog" print(Animals.CAT.name, type(Animals.CAT.name), Animals.CAT.value, type(Animals.CAT.value)) class Colors(str, Enum): BLUE = "blue" RED = "red" print(Colors.RED.name, type(Colors.RED.name), Colors.RED.value, type(Colors.RED.value)) Output: CAT <class 'str'> cat <clas
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.