Enums in Python are SO useful

preview_player
Показать описание
A little more loved than collections, but still in some need of attention. Maybe some ice cream will help?



If you enjoy my content, consider supporting me on Patreon (or hit the JOIN button below to become a member)!

If you need help with anything, feel free to join the Discord server:



If you have any questions, don't hesitate to ask in the comments! I'll try and answer as soon as I can, providing someone else hasn't already done so.

#python #enums #coding
Рекомендации по теме
Комментарии
Автор

Great summary! You can also iterate over enums, which can be very helpful in certain situations!

saxumnatur
Автор

Thanks for explaining with the application along with the Syntax
🙂

keerthi
Автор

Another benefit of enums is that you can check for Membership instead of checking for equality, which is more performant. For example in stead of checking `if state == State.PLAYING: ...` you can write it as `if state is State.PLAYING: ...`

tyrelllaszlo
Автор

One thing I wish Enums did is include the value name in the type representation of each Enum member.
it would make TypeErrors involving Enum members way more informative.

teslainvestah
Автор

There are so many other benefits of using enums, including that they can be type checked, exhaustiveness checking can be performed to make sure all possible states are accounted for etc. If you are going to make a video on enums being "so useful", might be worth going through those, instead of, "I just like them." Otherwise it looks like you're just making videos to get clicks.

jackgenewtf
Автор

Make a video on using enums with match statement, incase of non_matcing case like _ wildcard

SP-dbsh
Автор

Ive tried a few times but I keep stepping away from using enum. a follow-up vid showing explicit examples of typical scenarios without and then with enum and how enum makes it better would be very welcome.

jackrorystaunton
Автор

amazing as always, can u make a video about how to create a context manager I wanna make one for a db .. u know what I mean hh

xtz_
Автор

This should be included in builtin. For a Java/C#/modern C++ programmers like myself, this is a wonderful feature in order to empower my newly (re)acquired Python knowledge.

MohammadNajmiBachok
Автор

Enum values can't be mutable. #constant

sketchwaretagalogtutorials
Автор

I didn't know asa butterfield coded too

TheVideoVolcano
Автор

How to create new enum values after defining it.

See my code:

class Color(IntEnum):
RED = 0xFF0000
GREEN = 0x00FF00
BLUE = 0x0000FF

Now, I want to create new values by creating its object such as:

YELLOW = (0xFFFF00)
CYAN = (0x00FFFF)

But it gives me error "is not a valid Color"

How can I solve it?

Policy_Maker
Автор

Cumbersome way of defining enums, and it should be built in by default.

havenisse
Автор

I see no use for this. Maybe use a set? My opinion is that if you have a basic data structure that can do the job, it's almost always better to stick to it.

VkToo
Автор

I hate even leaving YouTube comments but you kinda never actually gave a definition of enums

musicmarketing
Автор

There's nothing clear about instantiating an enum...

pointer
Автор

"why not just use the string value? Well, it's just good practice!"
That doesnt answer anything. WHY is it good practice?

danielschmider