在python中进行枚举的公认方法是什么?
例如,目前我正在编写游戏,并且希望能够将“上”,“下”,“左”和“右”移动。我使用字符串是因为我还没有弄清楚枚举在python中是如何工作的,所以我的逻辑充满了这样的东西:
def move(self, direction):
if direction == "up":
# Do something
我想"up"
用类似的东西代替Directions.up
class Directions:
up = 0
down = 1
left = 2
right =3
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句