Enum 類別
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
在所有列舉類型中,Enum 類別屬於基本類型,用來初始化新的 Enum 執行個體。
Enum
由 protorpc.messages
模組提供。
建構函式
EnumField 類別的建構函式定義如下:
- class Enum(name, number=None)
-
建構類別時自動初始化 Enum 執行個體。整數和字串會自動轉換為列舉值。
引數
- name
- 要初始化的 Enumeration 例項名稱。
- number
- 要初始化的 Enumeration 例項數量。
如果呼叫的類別已經初始化,就會引發例外狀況。
類別方法
Enum 類別提供下列類別方法:
- to_dict()
- 建立為列舉類別的字典版本。您可以將字典搭配 def_num 與 import_enum 使用。
- 傳回列舉類別的字典名稱和編號。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-06-16 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-06-16 (世界標準時間)。"],[[["The `Enum` class serves as the foundation for all enumerated types and is used for initializing new `Enum` instances."],["The `Enum` constructor takes a name and an optional number to initialize an `Enum` instance, automatically casting integers and strings to enum values."],["The `to_dict()` class method generates a dictionary representation of the enumerated class, mapping names to numbers, for uses like `def_num` and `import_enum`."]]],[]]