Building Enumerations With Python's enum (Overview)
Some programming languages, such as Java and C++, have built-in support for a data type called enumerations, commonly referred to as enums. Enums enable you to create sets of logically related constants that you can access through the enumeration itself. Unlike these languages, Python doesn’t have a dedicated syntax for enums. However, the Python standard library provides an enum
module that offers support for enumerations through the Enum
class.
If you’re familiar with enums from other languages and wish to use them in Python, or if you simply want to learn how to work with enumerations, then this video course is designed for you.
In this video course, you’ll discover how to:
- Create enumerations of constants using Python’s
Enum
class - Interact with enumerations and their members in Python
- Customize enumeration classes by adding new functionalities
- Apply practical examples to gain a deeper understanding of the benefits of using enumerations
Additionally, you’ll explore other specific enumeration types available in the enum
module, such as IntEnum
, IntFlag
, and Flag
. These specialized enums will expand your repertoire.
To get the most out of this video course, you should be familiar with object-oriented programming and inheritance in Python.
00:00
Building enumerations with Python’s enum
.
00:04 Some programming languages such as Java and C++ include syntax that supports a data type known as enumerations or just enums. This data type allows you to create sets of semantically related constants that you can access through the enumeration itself.
00:21
Python doesn’t have a dedicated syntax for enums, but the Python Standard Library has an enum
module that supports enumerations through the Enum
class.
00:30 If you come from a language with enumerations and you are used to working with them, or if you just want to learn how to use enumerations in Python, then this course is for you.
00:39
In this course, you’ll learn how to create enumerations of constants using Python’s Enum
class, work with enumerations and their members in Python, customize enumeration classes with new functionalities and code practical examples to understand why you would use enumerations.
00:57
In addition, you’ll explore other specific enumeration types that live in the enum
module that will help you create specialized enums.
01:06 To follow along with this course, you should be familiar with object-oriented programming and inheritance in Python. After finishing this course, you may want to look deeper into these two subjects, and Real Python has you covered with this course on object-oriented programming,
01:22 and this one on inheritance.
01:26 Any code that you see running in the REPL will be using the bpython interpreter. This is a replacement Python interpreter that offers a number of enhancements, including code highlighting and suggestions.
01:36
But any code you see running on screen will work in the Python REPL, which is typically accessed by typing python
or python3
at your terminal or command line prompt. While enumerations were introduced in Python 3.4, parts of this course rely on language features introduced in Python 3.11, so you’ll need to be running that version or later to run all of the code examples seen.
02:01 So now you know what’s going to be covered. Let’s get started.
Become a Member to join the conversation.