How Can I Put Keywords Into My Code?

前端 未结 2 1336
花落未央
花落未央 2021-01-23 11:39

Okay so how could I make my code so instead of putting 1 to 4 I could just put in a keyword like \"Freezing\" or \"Froze\" How could i put a keyword searcher in my code, all hel

2条回答
  •  隐瞒了意图╮
    2021-01-23 12:07

    You are looking for an enum

    from enum import Enum
    class Status(Enum):
        NOT_ON = 1
        FREEZING = 2
        CRACKED = 3
        WATER = 4
    

    Then in your if checks, you do something like this:

    if problemselect == Status.NOT_ON:
        ...
    elif problemselect == Status.FREEZING:
        ...
    

提交回复
热议问题