Enums Explained In Under 12 Minutes In Python

Поділитися
Вставка
  • Опубліковано 25 лис 2024

КОМЕНТАРІ • 58

  • @cmv743a
    @cmv743a 2 місяці тому +27

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

    • @Indently
      @Indently  2 місяці тому +3

      I was fighting with autocomplete each time I wrote blue, and it still got me in the end!

  • @_DT_
    @_DT_ 2 місяці тому +55

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

    • @minepoint2794
      @minepoint2794 2 місяці тому

      4 Bit Binary:D (but without the last)

    • @Nbrother1234
      @Nbrother1234 Місяць тому

      @@minepoint2794So it’s 3 bit binary?

    • @minepoint2794
      @minepoint2794 Місяць тому +2

      @@Nbrother1234 Yes, that. I actually didn't know that existed 💀🤦‍♂

    • @Nbrother1234
      @Nbrother1234 12 днів тому

      Then PURPLE = 5?

    • @minepoint2794
      @minepoint2794 11 днів тому +1

      How come?

  • @theglobalsouth9680
    @theglobalsouth9680 2 місяці тому +13

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

  • @payton6_
    @payton6_ 2 місяці тому +6

    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

  • @efe099
    @efe099 2 місяці тому +2

    I was just planning to dive in to Enums thanks man

  • @dragweb7725
    @dragweb7725 2 місяці тому +10

    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 !

    • @Indently
      @Indently  2 місяці тому +6

      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!

  • @michaelhoffmann2891
    @michaelhoffmann2891 2 місяці тому

    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.

    • @Indently
      @Indently  2 місяці тому +3

      I just learned about IntEnum & StrEnum, will have a video out on that soon :)

  • @luffymonkey6967
    @luffymonkey6967 2 місяці тому

    great coverage of enums, thank you!

  • @danielcrompton7818
    @danielcrompton7818 2 місяці тому +1

    I’m so glad python added match case

    • @GameGame-rp4xc
      @GameGame-rp4xc 2 місяці тому

      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

  • @rakeshmarka6317
    @rakeshmarka6317 2 місяці тому

    Nice video 👍. Thank you !!

  • @withjk7
    @withjk7 2 місяці тому

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

  • @_a_x_s_
    @_a_x_s_ 2 місяці тому

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

  • @vegameta
    @vegameta 2 місяці тому +3

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

    • @sergiuszkot8116
      @sergiuszkot8116 2 місяці тому +1

      I don't understand what have you said but I am agree with you that StrEnum should be used there :)

    • @vanka_feelgood3000
      @vanka_feelgood3000 2 місяці тому +1

      Also IntEnum when you need integers

  • @kadircalloglu2848
    @kadircalloglu2848 2 місяці тому

    and also you can use bitwise

  • @josemanuelfernandez4999
    @josemanuelfernandez4999 2 місяці тому

    Awesome!!!!

  • @ppgiga
    @ppgiga 2 місяці тому

    I literally looked this up yesterday...

  • @murphygreen8484
    @murphygreen8484 2 місяці тому +9

    Hey Indently! Would you want to do a video refactoring someone's (mine) code?

    • @boboblacksheep5003
      @boboblacksheep5003 2 місяці тому +2

      Please refactor my code too 😂

    • @jamesford3282
      @jamesford3282 2 місяці тому +1

      are You guys real?

    • @murphygreen8484
      @murphygreen8484 2 місяці тому

      The code works and is a small program. Was thinking it could be like the code roasts that ArjanCodes does

    • @aflous
      @aflous 2 місяці тому +2

      ​@@murphygreen8484I am an experienced python dev and really like code roasting/refactoring. I've always wanted to start a UA-cam channel just to do that. Would you like me to start with yours?

  • @marionowera5602
    @marionowera5602 2 місяці тому

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

  • @aodhai
    @aodhai Місяць тому

    a lamp turning on an off and only having two states is literally a perfect case for a boolean and explicitly not an enum

    • @lukelauder5465
      @lukelauder5465 Місяць тому

      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? 😂

    • @aodhai
      @aodhai Місяць тому

      @@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

  • @Observer552
    @Observer552 2 місяці тому +2

    Is boolean actually an Enum with 2 constants?

  • @CrateSauce
    @CrateSauce 2 місяці тому

    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!

  • @KumR
    @KumR 2 місяці тому +3

    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 ?

    • @laurimauranen5685
      @laurimauranen5685 День тому

      It will save you from bugs, typos are common in programming.

  • @AndrewChikin
    @AndrewChikin 2 місяці тому

    Nice

  • @akashahmad4779
    @akashahmad4779 2 місяці тому

    Greate

  • @vicentcaselles4807
    @vicentcaselles4807 2 місяці тому

    What's the difference between using flags and sets?

    • @a-jjjjjjj
      @a-jjjjjjj 2 місяці тому +1

      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.

    • @urknidoj422
      @urknidoj422 2 місяці тому +1

      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.

  • @אלדרגארט
    @אלדרגארט 2 місяці тому

    9:02 you mistake blue with black (wrote black twice)

  • @rk_studio585
    @rk_studio585 2 місяці тому

    ❤❤

  • @AH-tx4ce
    @AH-tx4ce Місяць тому

    What is enum?

  • @DrDeuteron
    @DrDeuteron 2 місяці тому +4

    | is neither union nor addition, it’s bitwise or.

  • @lukelauder5465
    @lukelauder5465 Місяць тому +1

    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!

  • @compositeboson123
    @compositeboson123 2 місяці тому

    indently ı think my lamb is possesed what do ı do

    • @Indently
      @Indently  2 місяці тому

      If your lamp is turned on without electricity, you sell it to scientists and become a billionaire

    • @compositeboson123
      @compositeboson123 2 місяці тому

      @@Indently oh really ımma do t- *gets assasinated

  • @Microphunktv-jb3kj
    @Microphunktv-jb3kj Місяць тому

    never used python
    is python now statically typed language or smt ?

  • @rk_studio585
    @rk_studio585 2 місяці тому

    ❤❤