1、说明
(1)枚举成员未被排序,因此它们仅支持通过 is 和 == 进行比较。大小比较引发 TypeError 异常。
(2)继承 IntEnum 类创建的枚举类,成员间支持大小比较。
2、实例
import enum class BugStatus(enum.Enum): new = 7 incomplete = 6 invalid = 5 wont_fix = 4 in_progress = 3 fix_committed = 2 fix_released = 1 actual_state = BugStatus.wont_fix desired_state = BugStatus.fix_released print('Equality:', actual_state == desired_state, actual_state == BugStatus.wont_fix) print('Identity:', actual_state is desired_state, actual_state is BugStatus.wont_fix) print('Ordered by value:') try: print('\n'.join(' ' + s.name for s in sorted(BugStatus))) except TypeError as err: print(' Cannot sort: {}'.format(err)) # output # Equality: False True # Identity: False True # Ordered by value: # Cannot sort: '<' not supported between instances of 'BugStatus' and 'BugStatus'
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试