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.
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 !
I swear that when I was reading the docs a couple years ago I never noticed the Flag bit. Goes to show that re-reading the docs isn't always a bad idea!
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.
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.
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 ?
I was watching this video and thinking kinda: "is it really python? It doesnt have match statement when i started to learn it and even after 3 years using it - it is a first time i meet usage of match
@@murphygreen8484I am an experienced python dev and really like code roasting/refactoring. I've always wanted to start a TH-cam channel just to do that. Would you like me to start with yours?
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
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!
I mean… unless you want the words “ON” and “OFF” or something to be your return value or something… the joy of coding is there’s no universal truth and everything is subjective to one thing and one thing only: did it do what you wanted it to or not… I have lights that have 3+ states… ain’t no bool got that! Maybe a flag eh? EH? 😂
@@lukelauder5465 If i came across enums with on or off attached to them relating to the state of some class instead of using __repr__ or __str__ to represent that aspect of the class, id be in a bad way
They are conceptually very similar. Flags define the "universe" of the set, allowing certain operations like complements while also restricting what they can contain. Flags are also immutable and cannot be nested, unlike regular Python sets.
Using flags allows you to store multiple states in a single integer, which makes it more efficient to save and query in a database, compared to using sets.
It’s too bad he didn’t catch himself on ALL not being 31 rather than 27 because black was included in all instead of blue! Ha! I totally feel that typo tho… UGH!
FYI 9:04 it auto completed to black instead of blue.
Interesting video. Thanks
I was fighting with autocomplete each time I wrote blue, and it still got me in the end!
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.
python doing bitflags is nuts as heck. super awesome! i am ready to use it
i love bitflags
I came here thinking "ok, already know about enums". Then I just discovered Flag class. Awesome video. Thanks!
Flag works like:
RED = 1 (001)
GREEN = 2 (010)
BLUE = 4 (100)
ALL = 7 (111) because 001 | 010 | 100 = 111
4 Bit Binary:D (but without the last)
@@minepoint2794So it’s 3 bit binary?
@@Nbrother1234 Yes, that. I actually didn't know that existed 💀🤦♂
Then PURPLE = 5?
How come?
I was just planning to dive in to Enums thanks man
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 !
I swear that when I was reading the docs a couple years ago I never noticed the Flag bit. Goes to show that re-reading the docs isn't always a bad idea!
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.
great coverage of enums, thank you!
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.
I just learned about IntEnum & StrEnum, will have a video out on that soon :)
а для чего делать наследование от Enum для строковых значений? для таких случаев имеется StrEnum
I don't understand what have you said but I am agree with you that StrEnum should be used there :)
Also IntEnum when you need integers
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 ?
It will save you from bugs, typos are common in programming.
Above + in pattern matching static type checker will warn you if you don't exhaust all variants. I find it extremely useful.
I’m so glad python added match case
I was watching this video and thinking kinda: "is it really python? It doesnt have match statement when i started to learn it and even after 3 years using it - it is a first time i meet usage of match
Nice video 👍. Thank you !!
Hey Indently! Would you want to do a video refactoring someone's (mine) code?
Please refactor my code too 😂
are You guys real?
The code works and is a small program. Was thinking it could be like the code roasts that ArjanCodes does
@@murphygreen8484I am an experienced python dev and really like code roasting/refactoring. I've always wanted to start a TH-cam channel just to do that. Would you like me to start with yours?
please do one video on how to dind difference between instance and library vs package vs module
I think you shouldn't use str as type hint to enum members?
and also you can use bitwise
Is boolean actually an Enum with 2 constants?
No
Good question, but no. It's actually a subclass of Int in Python. 1 = True, 0 = False.
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
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!
Awesome!!!!
You forget the IntEnum which makes it quite useful to be stored as an integer constant directly into the database.
a lamp turning on an off and only having two states is literally a perfect case for a boolean and explicitly not an enum
I mean… unless you want the words “ON” and “OFF” or something to be your return value or something… the joy of coding is there’s no universal truth and everything is subjective to one thing and one thing only: did it do what you wanted it to or not… I have lights that have 3+ states… ain’t no bool got that! Maybe a flag eh? EH? 😂
@@lukelauder5465 If i came across enums with on or off attached to them relating to the state of some class instead of using __repr__ or __str__ to represent that aspect of the class, id be in a bad way
I literally looked this up yesterday...
What's the difference between using flags and sets?
They are conceptually very similar. Flags define the "universe" of the set, allowing certain operations like complements while also restricting what they can contain. Flags are also immutable and cannot be nested, unlike regular Python sets.
Using flags allows you to store multiple states in a single integer, which makes it more efficient to save and query in a database, compared to using sets.
| is neither union nor addition, it’s bitwise or.
Nice
9:02 you mistake blue with black (wrote black twice)
Greate
What is enum?
❤❤
indently ı think my lamb is possesed what do ı do
If your lamp is turned on without electricity, you sell it to scientists and become a billionaire
@@Indently oh really ımma do t- *gets assasinated
It’s too bad he didn’t catch himself on ALL not being 31 rather than 27 because black was included in all instead of blue! Ha! I totally feel that typo tho… UGH!
never used python
is python now statically typed language or smt ?
Plugins. Pyright/Ruff/MyPy, - the most popular.
❤❤