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

  介绍

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

python主要用来做什么

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

<强> 1,说明

(1)枚举成员未被排的序,因此它们仅支持通过和==进行比较。大小比较引发TypeError异常。

(2)继承IntEnum类创建的枚举类,成员间支持大小比较。

<强> 2,实例

 import 枚举
  ,
  ,
  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
  ,
  打印(& # 39;平等:& # 39;,
  ,,,,,actual_state ==, desired_state,
  ,,,,,actual_state ==, BugStatus.wont_fix)
  打印(& # 39;身份:& # 39;,
  ,,,,,actual_state  is  desired_state,
  ,,,,,actual_state  is  BugStatus.wont_fix)
  打印(& # 39;Ordered  by 价值:& # 39;)
  试一试:
  ,,,print (& # 39; \ n # 39; . join (& # 39;,, & # 39;, +, s.name  for  s 拷贝排序(BugStatus)))
  except  TypeError  as 错:
  ,,,print (& # 39;,, Cannot :, {} & # 39; .format (err))
  ,,,,
  #,输出
  #,平等:False 真正的
  #,身份:False 真正的
  #,Ordered  by 价值:
  #,,,Cannot :, & # 39; & lt; & # 39;, not  supported 结构;instances  of  & # 39; BugStatus& # 39;,以及& # 39;BugStatus& # 39; 

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

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