如何在 Python 類中使用列舉?
Python 中有一個名為 “enum” 的模組,可藉助它在 Python 中使用列舉。
#import enum
import enum
# use enum in class
class Car(enum.Enum):
suzuki = 1
Hyundai = 2
Dezire = 3
print ("All the enum values are : ")
for c in (Car):
print(c)
廣告
Python 中有一個名為 “enum” 的模組,可藉助它在 Python 中使用列舉。
#import enum
import enum
# use enum in class
class Car(enum.Enum):
suzuki = 1
Hyundai = 2
Dezire = 3
print ("All the enum values are : ")
for c in (Car):
print(c)