我写了一个可以输出三件事的函数:def getStatus(): if condition1: return "NormalStatus" elif condition2: return "ServerCompromised" elif condition3: return "UnknownStatus"如果我正在编写C ++代码,则将使用#define一些状态常量,它们只是整数,因此该函数不会每次都返回字符串。是否有Pythonic等效项可避免使用这样的字符串?我打算多次调用此函数,因此在输出上进行字符串比较可能比比较常量int慢得多。
添加回答
举报
0/150
提交
取消