menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Build Enum...
source image

RealPython

4w

read

124

img
dot

Image Credit: RealPython

Build Enumerations of Constants With Python's Enum

  • Python's enum module allows creating enumerations which is a data type to group related constants.
  • Enum class is used either by subclassing or functional API to create enum types.
  • Enumerations provide structure, offers prevention of reassignment and code readability.
  • Enums can work with data types like integers or strings, enhancing their flexibility.
  • Access to enum members can be with dot notation, call notation, or subscript notation.
  • Iteration over enum members is possible using loops and the members attribute.
  • Enumerations are immutable and discrete sets of constant values, representing limited possible variable values.
  • Python 3.4 added the Enum class to the standard library to support general-purpose enumerations.
  • The Enum class allows defining related constants as enum members.
  • Creating enumerations is easy by either subclassing Enum or using its functional API.

Read Full Article

like

7 Likes

For uninterrupted reading, download the app