新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

怎么在python中使用enum方法比较枚举

今天就跟大家聊聊有关怎么在python中使用enum方法比较枚举,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

10年积累的成都网站设计、做网站经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计制作后付款的网站建设流程,更有点军免费网站建设让你可以放心的选择与我们合作。

Python主要用来做什么

Python主要应用于:1、Web开发;2、数据科学研究;3、网络爬虫;4、嵌入式应用开发;5、游戏开发;6、桌面应用开发。

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'

看完上述内容,你们对怎么在python中使用enum方法比较枚举有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。


网页标题:怎么在python中使用enum方法比较枚举
当前路径:http://www.wjwzjz.com/article/geicgo.html
在线咨询
服务热线
服务热线:028-86922220
TOP