类似于java这种定义枚举变量的方式,一个变量(实则就是一个枚举对象变量)可以写入多个参数:
package test;
public enum TestEnum {
SUCCESS("0000","成功");
TestEnum(String code, String msg) {
this.code = code;
this.msg = msg;
}
private String code;
public String getCode() {
return code;
}
public String getMsg() {
return msg;
}
private String msg;
public static void main(String[] args) {
System.out.println(TestEnum.SUCCESS.getCode());
}
}
python实现其实更简单,其实也是类似于java中定义了一个实例变量:
from enum import Enum
class ApiCodeEnum(Enum):
def __init__(self, code, msg):
self.msg = msg
self.code = code
SUCCESS = "000000", "操作成功"
if __name__ == '__main__':
print(ApiCodeEnum.SUCCESS.msg)
参数个数看自己需求随便在后面加