python里使用enum库枚举类型的比较(二)
Python 类型 比较 枚举 Enum 使用
2023-09-14 09:10:35 时间
上一次,我们学习了枚举类型,发现它们不能进行比较,如果做这样的操作就会抛出异常,但是你还是想比较怎么办呢?比如C语言里一样,可以判断某一个范围的枚举值做一件事情。当然在python里也有方法解决的,它就是继承enum.IntEnum类,而不是enum.Enum,如下面的例子:
结果输出如下:
Ordered by value:
fix_released
fix_committed
in_progress
wont_fix
invalid
incomplete
深入浅出Numpy
五子棋游戏开发
http://edu.csdn.net/course/detail/5487
#python 3.6
#蔡军生
#http://blog.csdn.net/caimouse/article/details/51749579
#
import enum
class BugStatus(enum.IntEnum):
new = 7
incomplete = 6
invalid = 5
wont_fix = 4
in_progress = 3
fix_committed = 2
fix_released = 1
print('Ordered by value:')
print('\n'.join(' ' + s.name for s in sorted(BugStatus)))
结果输出如下:
Ordered by value:
fix_released
fix_committed
in_progress
wont_fix
invalid
incomplete
new
在这里可以使用sorted函数来进行排序枚举值。
深入浅出Numpy
http://edu.csdn.net/course/detail/6149
Python游戏开发入门
你也能动手修改C编译器
纸牌游戏开发
http://edu.csdn.net/course/detail/5538
五子棋游戏开发
http://edu.csdn.net/course/detail/5487
RPG游戏从入门到精通
http://edu.csdn.net/course/detail/5246
WiX安装工具的使用
http://edu.csdn.net/course/detail/5207
俄罗斯方块游戏开发
http://edu.csdn.net/course/detail/5110
boost库入门基础
http://edu.csdn.net/course/detail/5029
Arduino入门基础
http://edu.csdn.net/course/detail/4931
Unity5.x游戏基础入门
http://edu.csdn.net/course/detail/4810
TensorFlow API攻略
http://edu.csdn.net/course/detail/4495
TensorFlow入门基本教程
http://edu.csdn.net/course/detail/4369
C++标准模板库从入门到精通
http://edu.csdn.net/course/detail/3324
跟老菜鸟学C++
http://edu.csdn.net/course/detail/2901
跟老菜鸟学python
http://edu.csdn.net/course/detail/2592
在VC2015里学会使用tinyxml库
http://edu.csdn.net/course/detail/2590
在Windows下SVN的版本管理与实战
http://edu.csdn.net/course/detail/2579
Visual Studio 2015开发C++程序的基本使用
http://edu.csdn.net/course/detail/2570
在VC2015里使用protobuf协议
http://edu.csdn.net/course/detail/2582
在VC2015里学会使用MySQL数据库
http://edu.csdn.net/course/detail/2672
相关文章
- pycharm配置python运行环境_C中调用Python
- python常用面试题_Python+Selenium 常见面试题整理[通俗易懂]
- gyp ERR! stack Error: Can't find Python executable 'python'
- RStudio 改名 Posit,为了体现对 Python 和 VS code 社区的支持
- 【说站】python中__new__的重写
- 【说站】python中capitalize的三种转换操作
- 【说站】python导入模块的过程
- Python(一)对 meta class 的理解
- 【说站】python变长参数的使用注意
- 【说站】python闭包的特点
- 简述Python特点_python优缺点
- python里面的缩进是什么意思_Python缩进规则(一看即懂)[通俗易懂]
- 数据结构与算法Python_数据结构与算法python语言实现
- python deepcopy函数_Python deepcopy
- python数据可视化从入门到实战_大数据可视化概念
- 写外挂玩游戏啦-python自动化
- 9个Python 内置装饰器: 显著优化代码
- Python、MATLAB股票投资:ARIMA模型最优的选股、投资组合方案与预测
- Python变量:变量定义作用类型及特征
- Python面向对象编程-三大特性-继承-多继承
- Python线程-线程的互斥
- Python super()函数:调用父类的构造方法
- 什么是异常处理,Python常见异常类型(入门必读)
- Python的sorted函数应用详解编程语言
- Python bool类型和比较运算符(入门必读)
- Python与MongoDB 无缝连接(python连接mongodb)
- Python社区流行工具pip安装redis模块(pipredis)
- 使用Python进行新浪微博的mid和url互相转换实例(10进制和62进制互算)
- Python中模拟enum枚举类型的5种方法分享
- python进阶教程之动态类型详解