Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

Python  Module 9 – Object-oriented Python and the data model

Enums: Enum, IntEnum, StrEnum and Flag

Define fixed sets of named values with Python enums, look members up by name and value, choose between IntEnum and StrEnum, and combine options with Flag.

  • Intermediate
  • 20 minutes
  • Examples run with Python 3.14.8 and Pyodide 314.0.7
  • By MySmartCoPilot
Free core, Pro depth: 8 of 20 minutes free
Free: Each member has a name and a value, and exists once · Enum, IntEnum, StrEnum and Flag: what members also are · A case matches a member by its dotted name · Check yourself. With a pass: 2 in-depth parts and 3 interview answers, about 12 minutes.

What you will learn

  • Define an enumeration and read the name and value of its members
  • Find members by value and by name, and handle values that are not members
  • Choose between Enum, IntEnum, StrEnum and Flag for a task
  • Use auto(), @unique and Flag combinations correctly
  • Use enum members in match statements and state machines

Before you start

What you’ll learn · Before you start

What you will learn

  • Define an enumeration and read the name and value of its members
  • Find members by value and by name, and handle values that are not members
  • Choose between Enum, IntEnum, StrEnum and Flag for a task
  • Use auto(), @unique and Flag combinations correctly
  • Use enum members in match statements and state machines

Before you start

On this page

Five order statuses written as strings are five places for a typo: if status == "shiped": is never true, and nothing reports it. An enumeration (enum): A class whose members form a fixed, named set, such as the statuses of an order. Each member has a name and a value and is created once, when the class is defined; the enum module provides Enum, IntEnum, StrEnum and Flag., or enum, is a class whose objects form a fixed, named set, such as sizes, channels or permissions. Each enum member: One named value of an enumeration, such as OrderStatus.SHIPPED: an object created once with its class, with a name ("SHIPPED") and a value ("shipped"), that cannot be changed and is found again by value or by name. has a name and a value, is created once when the class is defined, and is compared with is or ==. Writing OrderStatus.SHIPPED instead of "shipped" turns a typo into an error at once, and lets editors and type checkers list every allowed value.

The enum module offers four kinds. Enum members are plain objects that never equal raw values. IntEnum members are also integers, and StrEnum members are also strings, so they compare equal to their values and go into JSON as they are. Flag members are bits that combine with | into sets of options. auto() chooses values for you, and @unique refuses two members with the same value. Below you will define an order status, compare the kinds and match on members.

Each member has a name and a value, and exists once

An order status with five members Python · order_status.py
from enum import Enum


class OrderStatus(Enum):
    PLACED = "placed"
    PACKED = "packed"
    SHIPPED = "shipped"
    DELIVERED = "delivered"
    CANCELLED = "cancelled"


status = OrderStatus.SHIPPED
print(status, repr(status), status.name, status.value)
print(OrderStatus("packed"), OrderStatus["DELIVERED"])  # by value, by name
print(status is OrderStatus("shipped"), status == "shipped", "shipped" in OrderStatus)
print(len(OrderStatus), [s.name for s in OrderStatus])

for attempt in ("lost", "SHIPPED"):
    try:
        OrderStatus(attempt)
    except ValueError as error:
        print("ValueError:", error)
try:
    status.value = "returned"
except AttributeError as error:
    print("AttributeError:", error)

Output

OrderStatus.SHIPPED <OrderStatus.SHIPPED: 'shipped'> SHIPPED shipped
OrderStatus.PACKED OrderStatus.DELIVERED
True False True
5 ['PLACED', 'PACKED', 'SHIPPED', 'DELIVERED', 'CANCELLED']
ValueError: 'lost' is not a valid OrderStatus
ValueError: 'SHIPPED' is not a valid OrderStatus
AttributeError: <enum 'Enum'> cannot set attribute 'value'

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 order_status.py

OrderStatus.SHIPPED, OrderStatus("shipped") and OrderStatus["SHIPPED"] all lead to the same member object.OrderStatus.SHIPPEDan attribute of the classOrderStatus("shipped")lookup by valueOrderStatus["SHIPPED"]lookup by namethe member SHIPPEDname: "SHIPPED"value: "shipped"one object, created once

Three ways to reach one enum member

Text description of the diagram

The diagram shows three expressions on the left, each with an arrow to the same box on the right.

  • OrderStatus.SHIPPED reads the member as an attribute of the class.
  • OrderStatus("shipped") looks the member up by its value.
  • OrderStatus["SHIPPED"] looks the member up by its name.

All three arrows end at one object: the member SHIPPED, whose name is "SHIPPED" and whose value is "shipped". It was created once, when the class was defined, so members can be compared with is as well as with ==.

  • OrderStatus.SHIPPED is a member. Its name is the identifier from the class body and its value the object assigned to it; its repr shows both.
  • OrderStatus("packed") finds a member by value, and OrderStatus["DELIVERED"] by name; the diagram shows all three ways to a member. A value that belongs to no member raises ValueError, which names the enum, and a name lookup with a wrong name raises KeyError.
  • Members are singletons, so the lookup returned the very same object, and is works. A plain member is never equal to its raw value: status == "shipped" is False. Since Python 3.12, "shipped" in OrderStatus checks the values.
  • The class is iterable in definition order and has a length, which makes enums handy for menus and validation.
  • Members cannot be changed: assigning to value raises AttributeError.

Use an enum whenever a variable may only hold one of a known set of values. Code that compares strings, such as if status == "shiped":, fails silently on a typo; OrderStatus.SHIPED fails loudly with AttributeError. The set has to be fixed in the code, though: product categories that shop staff add every week, or the list of countries in a form, are data, and belong in a database table or a file rather than an enum that needs a new release for every change.

Checkpoint

Check: Members, names and values

  1. Question 1 of 2 OrderStatus.SHIPPED has the value "shipped". What does OrderStatus("SHIPPED") do?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: It raises ValueError: 'SHIPPED' is not a valid OrderStatus

    order_status.py prints exactly this error. Parentheses look up by value, square brackets by name, and each kind of lookup has its own error.

  2. Question 2 of 2 Which of these are True for the OrderStatus of the program?

    Choose every answer that is right.

    Show the answer: Question 2 of 2

    Answer:

    • "shipped" in OrderStatus
    • OrderStatus("packed") is OrderStatus.PACKED

    The program prints True False True for the identity, the comparison with a string and the containment check, and 5 for the length.

Enum, IntEnum, StrEnum and Flag: what members also are

One example of each kind of enum Python · four_kinds.py
import json
from enum import Enum, Flag, IntEnum, StrEnum, auto


class Size(Enum):
    SMALL = 1
    LARGE = 2


class Priority(IntEnum):
    LOW = 1
    HIGH = 3


class Channel(StrEnum):
    EMAIL = auto()  # auto() in a StrEnum gives the lower-case name: "email"
    SMS = auto()


class Access(Flag):
    READ = auto()  # 1, 2, 4: one bit each
    WRITE = auto()
    SHARE = auto()


print("Enum:   ", Size.SMALL == 1, f"{Size.SMALL}")
print("IntEnum:", Priority.HIGH == 3, Priority.HIGH + 1, f"{Priority.HIGH}", sorted([Priority.HIGH, 2, Priority.LOW]))
print("StrEnum:", Channel.SMS == "sms", f"{Channel.EMAIL}", Channel.EMAIL.upper())
both = Access.READ | Access.WRITE
print("Flag:   ", both, Access.WRITE in both, Access.SHARE in both, list(both))
print(json.dumps({"priority": Priority.HIGH, "channel": Channel.SMS}))
try:
    json.dumps({"size": Size.LARGE})
except TypeError as error:
    print("TypeError:", error)

Output

Enum:    False Size.SMALL
IntEnum: True 4 3 [<Priority.LOW: 1>, 2, <Priority.HIGH: 3>]
StrEnum: True email EMAIL
Flag:    Access.READ|WRITE True False [<Access.READ: 1>, <Access.WRITE: 2>]
{"priority": 3, "channel": "sms"}
TypeError: Object of type Size is not JSON serializable

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 four_kinds.py

The table sums up what the program shows for each kind:

The four kinds of enum
Criterion EnumIntEnumStrEnum (3.11 and later)Flag
Members are also Nothing elseintstrCombinable bits
Equal to raw values NoYesYesNo
Printed and formatted as Size.SMALLThe numberThe stringAccess.READ|WRITE
When to choose States and choices inside a programCodes exchanged with C, databases or old APIsValues exchanged as text: JSON, URLs, settings filesSets of options that combine

Enum is the default, because it keeps members apart from everything else. IntEnum sorts and calculates with ints, which is right for numeric codes and wrong for anything else. StrEnum members format as their values and write themselves into JSON, and auto() in a StrEnum uses the lower-case member name as the value, so Channel.EMAIL is "email". Flag members each own a bit flag: One bit of a whole number used as a yes-or-no setting, so that several settings share one number: mode = READ | WRITE switches two on, and mode & WRITE tests one. More in “Type conversion, number bases and bitwise operators”; READ | WRITE is a combination, and in tests membership of one flag in a combination. A plain Enum member cannot be written to JSON as it is, which the last line of the example shows.

A quick way to choose: when the members never leave your program, use Enum. When another system already sends numbers, IntEnum saves a conversion at the boundary, and when it sends text, StrEnum does the same. When one value must hold several options at once, Flag is the only kind that combines them. The kinds arrived over several releases, which matters when your code must run on an older Python:

Timeline · 4 events in order When each kind of enum arrived Walk through the releases in order. Code that must run on an older Python can use only the kinds of its release.
  1. 3.4

    The enum module, with Enum and IntEnum

    PEP 435 added the enum module to the standard library. Enum and IntEnum date from this release.

  2. 3.6

    Flag, IntFlag and auto() new kinds

    Flag and IntFlag made members that combine with |, and auto() let the class choose the values.

  3. 3.11

    StrEnum, and IntEnum printed as a number new kind

    StrEnum arrived, with members that are also strings. In the same release str() of an IntEnum member became the str() of its int, so it prints as the number.

  4. 3.12

    in accepts values changed

    "shipped" in OrderStatus checks the values of the members. Before 3.12 a containment check with anything but a member raised TypeError.

The timeline has 4 events, from 3.4 to 3.12.

Checkpoint

Check: Enum, IntEnum, StrEnum and Flag

  1. Question 1 of 2 A partner's API sends "email" or "sms" in its JSON, and your program sends the same strings back. Which kind of enum saves a conversion at that boundary?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: StrEnum

    Choose by what the other side sends: text means StrEnum, numbers IntEnum, and values that never leave the program plain Enum.

  2. Question 2 of 2 both = Access.READ | Access.WRITE. What does Access.SHARE in both give?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: False

    four_kinds.py prints True for WRITE and False for SHARE: a Flag combination holds the bits of the members joined with |, and in tests them.

A case matches a member by its dotted name

A message for every status Python · match_status.py
from enum import Enum


class OrderStatus(Enum):
    PLACED = "placed"
    PACKED = "packed"
    SHIPPED = "shipped"
    DELIVERED = "delivered"
    CANCELLED = "cancelled"


def message(status):
    match status:
        case OrderStatus.PLACED | OrderStatus.PACKED:
            return "We are getting your order ready."
        case OrderStatus.SHIPPED:
            return "Your order is on its way."
        case OrderStatus.DELIVERED:
            return "Delivered. Enjoy!"
        case OrderStatus.CANCELLED:
            return "This order was cancelled."
        case _:
            raise ValueError(f"not an order status: {status!r}")


for status in OrderStatus:
    print(f"{status.name:<9} {message(status)}")
try:
    message("shipped")  # a string is not a member
except ValueError as error:
    print("ValueError:", error)

Output

PLACED    We are getting your order ready.
PACKED    We are getting your order ready.
SHIPPED   Your order is on its way.
DELIVERED Delivered. Enjoy!
CANCELLED This order was cancelled.
ValueError: not an order status: 'shipped'

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 match_status.py

In a case, a dotted name such as OrderStatus.SHIPPED is a value pattern: A dotted name in a case, such as case Status.SHIPPED:. Python looks the value up and compares the subject with ==, so it tests a constant without capturing. More in “Pattern matching with match and case”, compared with ==, and | combines several members into one case. A bare name would not work: case SHIPPED: is a capture pattern: A bare name in a case, such as case code:, which fits any subject and binds it to that name. It never compares, so case SHIPPED: overwrites a constant instead of testing it. More in “Pattern matching with match and case” that matches anything, and Python refuses it before other cases. Follow three subjects through the cases:

Interactive · stage by stage Three subjects through the cases of message() Step through match_status.py. Python tries the cases from the top and stops at the first that fits.
Three subjects through the cases of message(), step 5 of 5. Showing match status ('shipped', a str), PLACED | PACKED (no), OrderStatus.SHIPPED (no), DELIVERED, CANCELLED (no), case _ (ValueError: 'shipped'). In focus: OrderStatus.SHIPPED.match status'shipped', a strPLACED | PACKEDnoOrderStatus.SHIPPEDnoDELIVERED, CANCELLEDnocase _ValueError: 'shipped'case SHIPPED: refused

The drawing shows the whole scene; its 5 steps are listed below.

Every step as text
  1. PACKED. The loop passes OrderStatus.PACKED. The first case compares it with PLACED, which is not equal, then with PACKED, which is, so message() returns "We are getting your order ready."
  2. SHIPPED. OrderStatus.SHIPPED fails both comparisons of the first case and fits the second, so the message is "Your order is on its way."
  3. A plain string. message("shipped") gets a string. A plain Enum member is never equal to a raw value, so "shipped" fits none of the dotted names.
  4. The last case. case _ fits anything, and its body raises ValueError, so the string cannot slip through as if it were a status.
  5. A bare name. Writing case SHIPPED without the class name would make a capture pattern, which fits any subject and binds it to a new variable. Python refuses it before other cases, because they could never be reached.

The final case _: raises for anything that is not a member, so a plain string such as "shipped" cannot slip through as if it were a status. Static type checkers go one step further: they know every member of an enum, so they can warn when a match handles some statuses and forgets others, which a plain string never allows.

Checkpoint

Check: Matching members in case patterns

  1. Question 1 of 2 Why does message("shipped") reach case _ instead of case OrderStatus.SHIPPED?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: The case compares with ==, and a plain Enum member never equals a raw string

    Only case _ fits a string here, and its body raises ValueError, which is the point: a typo or a raw string cannot pass as a status.

  2. Question 2 of 2 Inside message(), someone writes case SHIPPED: as the first case, without the class name. What happens?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: Python refuses the match statement, because a bare name captures any subject and the later cases could never run

    Write members as dotted names in patterns, OrderStatus.SHIPPED, so that Python looks the value up and compares with ==.

Python Online Compiler Add a RETURNED status to OrderStatus and run match_status.py to see which line reports the new member.

Check yourself

Practice that adapts to you

Practise this lesson

10 questions about 8 ideas of this lesson. Each answer is explained at once, and what you get right is kept in this browser.

  1. Question 1 of 10 class Color(Enum): RED = "red". Which expression looks the member up by its value?

    Choose one answer.

    Show the answer: Question 1 of 10

    Answer: Color("red")

    Calling the class looks a member up by value; square brackets look it up by name, so Color["RED"] would work and Color["red"] raises KeyError. Color.RED.value goes the other way, from the member to its value.

  2. Question 2 of 10 What does status.value = "returned" do, for status = OrderStatus.SHIPPED?

    Choose one answer.

    Show the answer: Question 2 of 10

    Answer: It raises AttributeError, because members cannot be changed

    The program prints AttributeError: <enum 'Enum'> cannot set attribute 'value'. Members are constants, which is why they can be compared with is.

  3. Question 3 of 10 Shop staff add new product categories every week. Should the categories be an enum?

    Choose one answer.

    Show the answer: Question 3 of 10

    Answer: No, they are data that changes, so they belong in a database table or a file

    Use an enum when a variable may only hold one of a known set fixed in the code, such as order statuses. Sets that users extend are data.

  4. Question 4 of 10 perms = Access.READ | Access.WRITE. How do you test that perms includes WRITE?

    Choose one answer.

    Show the answer: Question 4 of 10

    Answer: Access.WRITE in perms

    in tests whether every bit of the left flag is set in the right one. perms == Access.WRITE is false, because perms holds two bits.

  5. Question 5 of 10 Which comparisons are True?

    Choose every answer that is right.

    Show the answer: Question 5 of 10

    Answer:

    • Channel.SMS == "sms", where Channel is a StrEnum with SMS = "sms"
    • OrderStatus("shipped") is OrderStatus.SHIPPED
    • Priority.HIGH == 3, where Priority is an IntEnum with HIGH = 3

    IntEnum and StrEnum members are also ints and strings, so they equal raw values. Plain Enum members equal only themselves. Members are singletons, so a lookup returns the very same object.

  6. Question 6 of 10 What does four_kinds.py print?

    What does this program print? Choose one answer.

    import json
    from enum import Enum, Flag, IntEnum, StrEnum, auto
    
    
    class Size(Enum):
        SMALL = 1
        LARGE = 2
    
    
    class Priority(IntEnum):
        LOW = 1
        HIGH = 3
    
    
    class Channel(StrEnum):
        EMAIL = auto()  # auto() in a StrEnum gives the lower-case name: "email"
        SMS = auto()
    
    
    class Access(Flag):
        READ = auto()  # 1, 2, 4: one bit each
        WRITE = auto()
        SHARE = auto()
    
    
    print("Enum:   ", Size.SMALL == 1, f"{Size.SMALL}")
    print("IntEnum:", Priority.HIGH == 3, Priority.HIGH + 1, f"{Priority.HIGH}", sorted([Priority.HIGH, 2, Priority.LOW]))
    print("StrEnum:", Channel.SMS == "sms", f"{Channel.EMAIL}", Channel.EMAIL.upper())
    both = Access.READ | Access.WRITE
    print("Flag:   ", both, Access.WRITE in both, Access.SHARE in both, list(both))
    print(json.dumps({"priority": Priority.HIGH, "channel": Channel.SMS}))
    try:
        json.dumps({"size": Size.LARGE})
    except TypeError as error:
        print("TypeError:", error)
    Show the answer: Question 6 of 10

    Answer: it prints

    Enum:    False Size.SMALL
    IntEnum: True 4 3 [<Priority.LOW: 1>, 2, <Priority.HIGH: 3>]
    StrEnum: True email EMAIL
    Flag:    Access.READ|WRITE True False [<Access.READ: 1>, <Access.WRITE: 2>]
    {"priority": 3, "channel": "sms"}
    TypeError: Object of type Size is not JSON serializable

    A plain member is not equal to its value and formats as Size.SMALL. IntEnum and StrEnum members format as their values and work in arithmetic, sorting, string methods and JSON. A plain Enum member is not something the json module can write.

  7. Question 7 of 10 A file of settings stores the sizes of a print job as "a4" or "letter", and a job may also ask for several finishing options at once: staple, punch and fold. Which kinds fit the two values?

    Choose one answer.

    Show the answer: Question 7 of 10

    Answer: A StrEnum for the size and a Flag for the finishing options

    One value at a time, exchanged as text: StrEnum. Several options at once: Flag, the only kind that combines its members.

  8. Question 8 of 10 Why must a case that matches an enum member use a dotted name, such as case OrderStatus.SHIPPED:?

    Choose one answer.

    Show the answer: Question 8 of 10

    Answer: A bare name such as case SHIPPED: is a capture pattern: it matches anything and binds it to a new variable

    In a pattern, a plain name captures the subject, and a dotted name is a value pattern that compares with ==. Python refuses case SHIPPED: before other cases with "makes remaining patterns unreachable".

  9. Question 9 of 10 What does message(OrderStatus.PLACED) return?

    Choose one answer.

    Show the answer: Question 9 of 10

    Answer: "We are getting your order ready."

    | combines several members into one case, and the cases are tried from the top, so PLACED stops at the first.

  10. Question 10 of 10 You add RETURNED = "returned" to OrderStatus and change nothing in message(). What happens when the loop of match_status.py reaches the new member?

    Choose one answer.

    Show the answer: Question 10 of 10

    Answer: message() raises ValueError, from case _, because no case names RETURNED

    The error names the new member, so the gap is found at once. A static type checker can warn even earlier, because it knows every member of the enum.

Flags, aliases and stored values in depth: three traps reproduced Pro: opens with a Pro, Premium or Ultimate pass

Flags pack several options into one value, and they behave in ways a plain enum never does. Aliases, comparisons between unrelated integer enums and stored auto() values cause quiet bugs that show up only in production data; each is reproduced below.

In this part:

  • Permission flags: grant, revoke, test and name combinations
  • Members that carry data and behaviour
  • Three traps: aliases, unrelated IntEnums and auto() values on disk

1 diagram · 3 runnable examples (Python) · about 7 minutes

Opening this part with your pass…

This part opens with any MySmartCoPilot pass.

  • Pro pass · 1 week₹79$2.99
  • 30 days₹179$5.99
  • 1 year₹1,699$45

One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

Enums in real code: a state machine, JSON with old values, and an exercise Pro: opens with a Pro, Premium or Ultimate pass

Enums earn their keep at the edges of a program, where statuses change and values arrive from outside. This part builds an order state machine with a completeness check, reads and writes enum values as JSON, accepts legacy spellings with _missing_, and ends with an exercise that combines a state cycle with flags.

In this part:

  • An order state machine driven by an enum
  • JSON and old spellings, accepted by one hook
  • Exercise: a traffic light and permission flags
  • A traffic light that refuses bad changes, and permission flags
    • Results of the sample tests

3 diagrams · 2 runnable examples (Python) · 1 exercise with sample tests · about 9 minutes

Opening this part with your pass…

This part opens with any MySmartCoPilot pass.

  • Pro pass · 1 week₹79$2.99
  • 30 days₹179$5.99
  • 1 year₹1,699$45

One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

Interview questions

  1. Fresher · Warm-up

    Why use an enum instead of plain string constants such as "shipped" for an order's status?

    An enum makes the set of allowed values part of the code. With strings, a typo such as "shiped" is just another string: comparisons are quietly false and the bug appears far away. With an enum, OrderStatus.SHIPED raises AttributeError at once, and OrderStatus("shiped") raises ValueError when outside data arrives. The class also lists every allowed value, so code can iterate over them, editors can complete them and type checkers can tell when a match statement forgets one. Members are singletons with a name and a value, and the value can still be a string for JSON or a database. Plain Enum members never equal raw strings, which keeps statuses from being mixed with other text; StrEnum keeps that equality when compatibility with strings matters more.

  2. Mid to senior

    Two IntEnums, Priority and Retries, each have a member with the value 3. A bug report says high-priority jobs are sometimes treated as jobs that allow three retries. How can that happen, and what would you change?

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page. First step and follow-ups

  3. Mid to senior

    Order statuses are an IntEnum with auto() values, stored as integers in a database. A developer adds a new status in the middle of the class. What breaks, how would you detect it before release, and how should statuses be stored?

    Model answer, Pro. First step and follow-ups

  4. Senior to staff

    You are designing user permissions for a document service. Would you use a Flag, a set of Enum members, or a table of grants in the database? Compare them for storage, checking, querying and adding permissions later.

    Model answer, Pro. First step and follow-ups

Key takeaways

  • An enum is a fixed set of named members, each with a name and a value; members are singletons.
  • Kind(value) looks a member up by value and Kind["NAME"] by name; a missing value raises ValueError.
  • Plain Enum members never equal raw values; IntEnum and StrEnum members are also ints and strings.
  • Flag members combine with | and are tested with in; match members with dotted names in case patterns.

Terms in this lesson

enum member
One named value of an enumeration, such as OrderStatus.SHIPPED: an object created once with its class, with a name ("SHIPPED") and a value ("shipped"), that cannot be changed and is found again by value or by name.
enumeration (enum)
A class whose members form a fixed, named set, such as the statuses of an order. Each member has a name and a value and is created once, when the class is defined; the enum module provides Enum, IntEnum, StrEnum and Flag.

References

Related tools

Report a problem with this lesson

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.