10 Neat Ways To Use Underscore In Python

Sdílet
Vložit

Komentáře • 71

  • @landsgevaer
    @landsgevaer Před 18 dny +30

    Hello Bob!
    BTW, in the final example with "case _", the underscore also acts like any variable, matching true to any expression and capturing it.

    • @jamesarthurkimbell
      @jamesarthurkimbell Před 18 dny +3

      It doesn't capture in the sense of assignment to the name, e.g. you can say
      case x: return f"{x} not found"
      but if you tried something like
      case _: return f"{_} not found"
      you would get a name error

    • @BobChess
      @BobChess Před 18 dny +2

      Hello

  • @troshujin
    @troshujin Před 18 dny +7

    Hey, I'm loving these videos!
    I consider myself pretty good at python so I started watching to make sure I'm not missing any knowledge.
    But instead I find myself watching your videos just because I enjoy them!

    • @Indently
      @Indently  Před 18 dny

      Really appreciate it! Makes me happy to hear this :)

    • @troshujin
      @troshujin Před 18 dny

      @@Indently Please keep making videos! I'll be eagerly waiting!

    • @aaronvegoda1907
      @aaronvegoda1907 Před 18 dny

      Same. I really enjoy these. They are concise, informative, and I find find them quite relaxing. :)

    • @nosdok74
      @nosdok74 Před 18 dny

      ditto

  • @twindrawingstudio
    @twindrawingstudio Před 18 dny +2

    Thanks you 🎉

  • @banjohead66
    @banjohead66 Před 18 dny +28

    I was surprised that you didn't cover this in the number formatting segment but the underscore can also be used as an f-string formatter to render large numbers:
    my_big_int: int = 1242998325235625656975629564965932645346536952465
    print(f"{my_big_int:_}") #

    • @rusektor
      @rusektor Před 18 dny +2

      Wow, this is cool! :)

    • @banjohead66
      @banjohead66 Před 18 dny

      @@rusektor You can do a comma instead of the underscore for comma separation -- cool stuff!

    • @rusektor
      @rusektor Před 18 dny +1

      @@banjohead66 Oh! That works! Is there also something interesting? ))) I know that I can write print(f"{num = }" instead of print(f"num = {num}") 🙂

    • @banjohead66
      @banjohead66 Před 17 dny

      @@rusektor Yeah! I use that one all the time! It's incredibly useful/convenient!

    • @portalwalker_
      @portalwalker_ Před 16 dny +2

      ​@@rusektor He made a whole video about cool f-string syntax where he covered this number formatting and other useful tricks

  • @SebastianGuzman322
    @SebastianGuzman322 Před 17 dny +2

    Hi Bob!
    Loved the vid, thanks a lot :)

  • @norbertdapunt1444
    @norbertdapunt1444 Před 18 dny +1

    Awesome.

  • @romankrt7879
    @romankrt7879 Před 12 dny +1

    I like the underscore for tuple unpacking esp. when you only need one value from a whole bunch. As the underscore is a "throw away variable" you can use it more than once. For example you only want the profession from the following, poorly created example, you can unpack it like this:
    ("Bob", "Smith", "Developer", "Python") = _, _, profession, _

  • @kapibara2440
    @kapibara2440 Před 12 dny

    Good one!

  • @JuanPerez-iu9vk
    @JuanPerez-iu9vk Před 16 dny

    TY

  • @Random-Boy_py
    @Random-Boy_py Před 16 dny +2

    Hi Bob!

  • @animesh5298
    @animesh5298 Před 16 dny +3

    Can you please also make a game in python.??

  • @hitwhy
    @hitwhy Před 16 dny

    hi, I like your videos and so bought all your lessons on udemy. Hope I can grasb python! Thank you for the videos!

    • @Indently
      @Indently  Před 16 dny +1

      Glad to hear you enjoy the videos! Thank you for the support! Happy learning :)

  • @zippy66666
    @zippy66666 Před 18 dny

    Gr8 m8

  • @mshonle
    @mshonle Před 17 dny +2

    Thumbs up for “in modern English known as a comma”. 😂

  • @dm_kael
    @dm_kael Před 18 dny +1

    Hello, Bob!

  • @ReynoldChua
    @ReynoldChua Před 18 dny +2

    Thank for the great tips. Being new to python and learning it from books, I noticed that all you variable declaration are followed by colon (Ex: values: list[int] = ...) as well as declaring the return type of functions or methods. Is this a new version of Python? Does Python enforces this like in other languages? Initially, I was confused reading the code such as "state: tuple[str, str, int] = ('Bob', 'Programmer', 27)" as most books I read don't use that format and other languages use the other way (Ex: int score = 75).

    • @dragweb7725
      @dragweb7725 Před 18 dny +4

      it is called "type annotation" or "type hint", it is a feature that is not enforced by python, the python interpreter even ignores it, but it is good practice to use it for several reasons:
      1) Dynamic code editors (pycharm, VSCode, etc...) will use them to infer variable types and warn you when type hint and value do not match
      2) the same code editors can better help you with apropriate contextual propositions when you call methods on your variables
      3) type hinting arguments in functions makes said function more self-explanatory, it is part of a good clear documentation
      4) if you install a static python type checker such as mypy, it is useful for it to work as expected

    • @callbettersaul
      @callbettersaul Před 18 dny +1

      Type annotations were introduced in python 3.5, which was released 10 years ago (in 2014), so no, it's not a new feature.

    • @alexandertownsend5079
      @alexandertownsend5079 Před 13 dny

      The Python language has multiple versions. Which version was your book teaching?

  • @syrupthesaiyanturtle
    @syrupthesaiyanturtle Před 5 dny

    what is the Self type used for and how do you use it?

  • @KroshkaMu
    @KroshkaMu Před 11 dny +1

    Hello Bob!

  • @Ungerlogik
    @Ungerlogik Před 18 dny

    Hi Bob, when did you learn python?

  • @hedwig7s
    @hedwig7s Před 13 dny

    By the way in the 2nd example you mixed up camelCase and PascalCase

  • @QBitDevs
    @QBitDevs Před 11 dny

    What's the code edittor and plug in?

  • @mrbutish
    @mrbutish Před 18 dny +1

    Cool_cool_cool_😬

  • @U53RN07F0UND
    @U53RN07F0UND Před 18 dny +1

    Name mangling. I never realized how awkward this term is. "namangling".
    Almost forgot... Hi Bob!

  • @atorrres
    @atorrres Před 10 dny +1

    Olá Bob!!!

  • @avichaicohen3140
    @avichaicohen3140 Před 7 dny

    🚀💥

  • @y2ksw1
    @y2ksw1 Před 18 dny +2

    English American have been bad with Numbers, too. The confusion is perfect after the million

    • @U53RN07F0UND
      @U53RN07F0UND Před 18 dny

      I also am English American and have been very bad with Numbers, too.
      Such perfect confusion...

  • @omegaroyal
    @omegaroyal Před 9 dny

    Use _('string to translate ')

  • @MrSunTrope
    @MrSunTrope Před 17 dny

    Yee, i knew it

  • @edwardtafadzwafusire9243

    Hello Bob

  • @tullman3craggs102
    @tullman3craggs102 Před 18 dny

    I'm going to come clean guys... I use snake case for
    functions eg do_this_thing and camel? For variables eg newVar, constants stay capital, anyone have a better idea to maintain readability of all the different methods/vars?

    • @U53RN07F0UND
      @U53RN07F0UND Před 18 dny

      I generally find it best to adhere to the conventions of whichever language I'm programming in.
      So in C, snake_case_for_variables_and_functions, camelCaseForTypedefsAndStructs, and, UPPER_SNAKE_CASE_FOR_CONSTANTS_AND_MACROS.
      In Java, camelCaseForVariablesAndMethods, PascalCaseForClassesAndInterfaces, UPPER_SNAKE_CASE_FOR_CONSTANTS, and, dot.case.for.packages.
      Other devs expect these conventions to be upheld and many mistakes can be avoided by keeping your code consistent with them.

    • @mikefochtman7164
      @mikefochtman7164 Před 14 dny +1

      One project, they set the 'standard' to use camel case for vars and funcs, but for vars the first letter was always lower case. So something like:
      myAge: int = 42
      UpdateAge(currentAge: int) -> int
      return curretAge+1
      But some folks don't care so much, others get quite passionate. Use something but most important, stick with your choice.

    • @U53RN07F0UND
      @U53RN07F0UND Před 14 dny +2

      @@mikefochtman7164 Agreed. The most important thing is that your code is consistent. FYI, the first letter of the variable being lowercase is camel-case. If the first letter is upper case along with the first letter of all other words in the variable name, it's Pascal-case.

  • @adudeandacat
    @adudeandacat Před 18 dny

    I think the only way to make anything "private" is using a decorator/wrapper, right?

    • @vlc-cosplayer
      @vlc-cosplayer Před 16 dny +1

      There's no such thing as "private", ever! Even in languages with managed runtimes, if you find an arbitrary code execution bug, you can read any piece of memory or execute any piece of code, including those marked as private. 👀

    • @falklumo
      @falklumo Před 15 dny

      ⁠@@vlc-cosplayerIn Java with Security Manager enabled, you‘ll have a hard time as such bugs are considered harmful and chased down quickly.

  • @orasul78
    @orasul78 Před 18 dny

    In 8-th You didn’t mention if hidden id is still accessible via self.__hidden_id inside the class definition.

    • @arnoldlayne585
      @arnoldlayne585 Před 18 dny

      It is, otherwise what would be the point? store unnecessary data?

  • @ego-lay_atman-bay
    @ego-lay_atman-bay Před 2 dny

    Wait, name mangling exists?

  • @hitaishi2222
    @hitaishi2222 Před 18 dny

    Hey bob..

  • @juschu85
    @juschu85 Před 14 dny

    A variable/function you can(/should) only use in its class OR subclass is not (semi)private, that's (semi)protected. When it's (semi)private, it also can't(/shouldn't) be used in a subclass.
    I really wonder why you don't have any actual private or protected variables/functions you CAN'T even use somewhere else even if you would try. That's pretty standard in other object oriented languages like C++, C#, Java, or PHP and I don't see a reason why Python shouldn't have this.

  • @alvercury
    @alvercury Před 18 dny

    How's it going, Bob?

  • @Rodakot
    @Rodakot Před 18 dny

    Hello _!

  • @philluvschips3787
    @philluvschips3787 Před 17 dny

    If your example were in an array you would count from 0, so there would be eleven examples.

  • @tema5002
    @tema5002 Před 15 dny

    i think you already made that video?

  • @PaulPhillabaum
    @PaulPhillabaum Před 17 dny

    Who is Bob?

  • @DrDeuteron
    @DrDeuteron Před 18 dny

    My underscore game is weak.

  • @timurotube
    @timurotube Před 15 dny

    what Bob did to you?)))

  • @mahdoosh1907
    @mahdoosh1907 Před 18 dny

    still no comments :( im telling this instead of "im second"

  • @michieleding1242
    @michieleding1242 Před 9 dny +1

    So i guess you dont use your brain to read 1_000_000_000_000

  • @BhEaN
    @BhEaN Před 18 dny +1

    Hi Bob!

  • @jeffreyphipps1507
    @jeffreyphipps1507 Před 17 dny

    Hi Bob!