enum in Python:

The enum module is used for enumerations in Python. For the creation of enumerations, we use classes. Enums have association with names and values.

Properties of enum module:

  • The enums can be displayed as string or repr.
  • To check enums for types, we use type().
  • To display the name of the enum member, we use the name

  • Enumerations are iterable in nature. Loops are used for iterating them.
  • Hashing is supported by enumerations. Enums are useful in dictionaries or sets.

Accessing of enum:

To access enum, we have two methods,

  • By value: The value of the enum member is passed in this method.
  • By name: The name of the enum member is passed in this method.

We can access separate value or name by using name or value keyword.

Comparisons in enum:

There are two types of comparisons supported in enumerations.

  • Identity: To check these we use the keywords is and is not.
  • Equality: In enum equality comparisons of “==” and “!=” types are supported.

 

Leave a Reply

Your email address will not be published. Required fields are marked *