Enums

The keyword enum introduces an enumerated type, a set of name to integer value associations.

enum Python:
     Eric
     John
     TerryG
     TerryJ
     Graham
     Michael

which is equivalent to:

enum Python:
     Eric = 0
     John = 1
     TerryG = 2
     TerryJ = 3
     Graham = 4
     Michael = 5

Extracting the integer value of a enum is just a matter of casting it to an int:

print(cast(int, Python.TerryG)*2) # prints 4

Labels

 
(None)