如何在 Python 類中使用列舉?


python 有一個名為“enum”的模組,其作用是幫助 pyhon 使用列舉。

#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)

更新於:2020 年 6 月 23 日

195 次瀏覽

開啟你的 職業生涯

完成課程以獲得認證

開始
廣告
© . All rights reserved.