Enums Explained In Under 12 Minutes In Python

preview_player
Показать описание
In today’s video we’re going to be learning about the basics of enums in Python. We will also be covering what a Flag is and how to use the auto() feature.

▶ Become job-ready with Python:

▶ Follow me on Instagram:
Рекомендации по теме
Комментарии
Автор

FYI 9:04 it auto completed to black instead of blue.
Interesting video. Thanks

cmva
Автор

python doing bitflags is nuts as heck. super awesome! i am ready to use it

theglobalsouth
Автор

Flag works like:
RED = 1 (001)
GREEN = 2 (010)
BLUE = 4 (100)
ALL = 7 (111) because 001 | 010 | 100 = 111

_DT_
Автор

I came here thinking "ok, already know about enums". Then I just discovered Flag class. Awesome video. Thanks!

luismolon
Автор

Very good and clear explanation of enums, especially flags. What I'm missing is:
- getting the value and the name of the enum constant (either one is sometimes useful e.g. in printing the selected value, logs, converting the selection to, let's say, SQL query),
- StrEnum type (if the enum constants have to be strings, it's easier to get the string value out of StrEnum than an Enum),
- iterating over all values of an enum type (useful e.g. with GUI constrols, like a dropdown).
But overall, a very good introduction.

piotrrybka
Автор

I was just planning to dive in to Enums thanks man

efe
Автор

i knew about Enums, but not about Flags ! Maybe i really should check the whole documentation of the enum package, it seems it haven't revealed all its best secrets yet !

dragweb
Автор

This is a cool feature. I usually just create a module that contains a bunch of constants in cases like this. I think I'll start using an Enum class instead.

gibbytravis
Автор

please do one video on how to dind difference between instance and library vs package vs module

withjk
Автор

I find I use StrEnum with auto() somewhat frequently, though its usefulness some would debate. It's nice to have one clear place to replace a string, rather than having trust my IDE to do a find/replace exactly where I want it.

michaelhoffmann
Автор

As someone leaning python I'm slightly confused what use cases you would use this for. Can someone give hypothetical use cases for this function?

littlegreen
Автор

а для чего делать наследование от Enum для строковых значений? для таких случаев имеется StrEnum

vegameta
Автор

Is boolean actually an Enum with 2 constants?

Observer
Автор

I think you shouldn't use str as type hint to enum members?

marionowera
Автор

I literally looked this up yesterday...

ppgiga
Автор

For those watching: please don’t use f-strings if you aren’t going to use the functionality of f-strings. Readability comes in to play here due to intent

payton_
Автор

You forget the IntEnum which makes it quite useful to be stored as an integer constant directly into the database.

_a_x_s_
Автор

Thank you for finding us this info...However, Is enum really essential ? I am not able to comprehend why would it be needed ? Just for cleaner looking code ?

KumR
Автор

Hey man, this video is great! I cant stop hearing you talk about Colas tho lol.
Color is pronounced CUH-ler in the US and CUH-luh in the UK
Thanks for the tutorial!

CrateSauce
Автор

so a Flag is acting as a bitmask which can be used for assigning multiple states while an Enum is better for exclusive states.

FayolaOnline