20 Everyday Tips & Tricks in Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ต.ค. 2024

ความคิดเห็น • 60

  • @mateuszzebala
    @mateuszzebala 3 หลายเดือนก่อน +28

    "It's cool because there is Bob" 😂

  • @cefarix
    @cefarix 3 หลายเดือนก่อน +7

    Just wanted to point out that defining __ call __ on a class makes _instances_ of that class callable not the class itself. All classes are callable anyways since that's how you create new instances.

  • @Владислав-м3е9г
    @Владислав-м3е9г 3 หลายเดือนก่อน +7

    21:40 - I would use regex here, as instead of spaces there might be some other separations + upper case problem would be solved as well

    • @aaronvegoda1907
      @aaronvegoda1907 3 หลายเดือนก่อน +1

      Yeah, 're' is amazing

  • @DrDeuteron
    @DrDeuteron 3 หลายเดือนก่อน +4

    No 15: overloading repr() is a good idea. You can also use "type(self).__name__" or self.__class___.__name__ instead of the explicit "Person" in the f-string.

  • @GOPINATH-jx1su
    @GOPINATH-jx1su 2 หลายเดือนก่อน +2

    2:59
    Tip no 1:😅
    No need to use number%2==0 there instead use number%2 only, because number%2 always gives you either 0 or 1,if 0 => False, if 1 => True😅❤
    Note: change Even as Odd and Odd as Even😅😂
    Good Teaching❤

  • @lesheq85
    @lesheq85 3 หลายเดือนก่อน +2

    i can't believe you typed "odd" with zero instead of capital 'o'... this is bothering me...

  • @richardbennett4365
    @richardbennett4365 3 หลายเดือนก่อน +3

    What happens if one gets from the dictionary, "Bob" instead of getting "name?"

  • @rubenvanderark4960
    @rubenvanderark4960 3 หลายเดือนก่อน +11

    21:44
    If you replace just " red" with " blue", the string " reduced" would still turn into " blueduced".
    Also, the string "red" would be unchanged because it doesn't start with a space.

    • @mk00088
      @mk00088 3 หลายเดือนก่อน +3

      In that case we can use *re.sub*

    • @shittuto
      @shittuto 22 วันที่ผ่านมา

      use " red " in that case. space before and after. with " blue " .

  • @richardbennett4365
    @richardbennett4365 3 หลายเดือนก่อน +1

    print(*_) gives a space-delimited row of names, not a list object.
    😮
    Ha ha ha.

  • @mudi2000a
    @mudi2000a 3 หลายเดือนก่อน +3

    Regarding default values for dictionaries, you should also have a look at the collections.defaultdict class which I find very useful. There you can specify a general default value that you get if the key doesn't exist. This is very useful e.g. if you want to count something.

    • @DavideCanton
      @DavideCanton 3 หลายเดือนก่อน +2

      Another alternative is subclassing dict and defining the __missing__ method. It has the bonus of providing the key to compute the default dynamically

  • @jeffreyphipps1507
    @jeffreyphipps1507 3 หลายเดือนก่อน +2

    #13 "Bob, who's obviously named Jeff" - gets me every time... 🤣🤣🤣

  • @laytonjr6601
    @laytonjr6601 3 หลายเดือนก่อน +1

    Using replace(' thing', ' other') doesn't work for words that start with thing (the same way replace('thing ', 'other ') doesn't work for words that end with thing (and if the character behind it is not a space, for exemple a period or a comma, it won't work either)

    • @aaronvegoda1907
      @aaronvegoda1907 3 หลายเดือนก่อน +1

      Included with the python std lib there is a module called 're' that allows you to find and replace using regex

  • @rokaskarabevicius
    @rokaskarabevicius 3 หลายเดือนก่อน +1

    Python is beautiful, but counter: Counter = Counter() is just not ZEN.

    • @chrisdieguez1950
      @chrisdieguez1950 3 หลายเดือนก่อน

      I know, right? Get yer dang Java outta my Python

    • @chrisdieguez1950
      @chrisdieguez1950 3 หลายเดือนก่อน

      I know right? Get yer dang Java outta my Python!

  • @enksek
    @enksek 2 หลายเดือนก่อน

    what kind of syntax is this a: str="text" ?
    normally I just write a="text"
    never seen before in python.

  • @Heavy_Lvy
    @Heavy_Lvy 2 หลายเดือนก่อน

    what i prefer in string multifaction is using an f string f'{'A'*20}H!'

  • @cdm1972
    @cdm1972 หลายเดือนก่อน

    Lot of great tips in this vid. Probably will watch again later, lol.

  • @theorange6460
    @theorange6460 3 หลายเดือนก่อน +2

    I use these tricks everyday

  • @richardbennett4365
    @richardbennett4365 3 หลายเดือนก่อน

    He wrote the numeral zero in the word "Odd" instead of the capital letter O. 😮

  • @richardbennett4365
    @richardbennett4365 3 หลายเดือนก่อน

    If one wants to comvine two dicrionaries a and b, then why not simply a + b?

  • @ChXXL
    @ChXXL 2 หลายเดือนก่อน

    Some tips really helped me. Thanks!

  • @syrupthesaiyanturtle
    @syrupthesaiyanturtle 3 หลายเดือนก่อน +1

    23:50 you can also use a tuple as a key to achieve multilayer sorting such as min(names, key = lambda name: (name.lower().count('a'), name))

    • @olfmombach260
      @olfmombach260 2 หลายเดือนก่อน

      Very interesting, didn't think of that

  • @Muso-c8j
    @Muso-c8j 2 หลายเดือนก่อน

    what is the difference __str__ and __repr__

  • @369Gamer
    @369Gamer 3 หลายเดือนก่อน +1

    Your content is very useful

  • @luketurner314
    @luketurner314 3 หลายเดือนก่อน

    11:15 for those in a country that swaps the decimal and comma in numbers:
    f'{big_number:_}'.replace('.', ',').replace('_', '.')

  • @anon_y_mousse
    @anon_y_mousse 3 หลายเดือนก่อน

    As a corollary to multiplying strings and arrays, I overloaded / so that I could divide them as well. Take for instance "ababab"/"ab" would yield 3, and "bababa"/3 would yield "ba". You could probably make a video on showing an implementation of that. It would likely be better than mine.

  • @wujublazedman6984
    @wujublazedman6984 3 หลายเดือนก่อน +2

    33 sec ago was wild

  • @vslabs-za
    @vslabs-za 3 หลายเดือนก่อน

    Poor Bob, being byte by like 20 small pythons... sheez...

  • @Chaminox
    @Chaminox หลายเดือนก่อน

    damn actually useful

  • @alexcaffri9091
    @alexcaffri9091 9 วันที่ผ่านมา

    aHHHhhaa (!)

  • @吳政霖-b9t
    @吳政霖-b9t 3 หลายเดือนก่อน

    13:21
    ... it looks quite confusing.
    Haskell: Good luck!

  • @JG-gy3tt
    @JG-gy3tt 3 หลายเดือนก่อน

    Great video. My interest was peaked while watching.

  • @christopheanfry2425
    @christopheanfry2425 3 หลายเดือนก่อน

    Thank you for this very useful video. Can I ask you what theme you use in Pycharm?

    • @novamc7945
      @novamc7945 3 หลายเดือนก่อน

      pretty sure he uses the default

  • @troshujin
    @troshujin 3 หลายเดือนก่อน

    Yeah another indently vid! :D

  • @arb6t9
    @arb6t9 3 หลายเดือนก่อน

    He made python more simpler

  • @loverboykimi
    @loverboykimi 3 หลายเดือนก่อน

    This is Gold!

  • @BobChess
    @BobChess 3 หลายเดือนก่อน

    I love python

  • @יהבלזר
    @יהבלזר 3 หลายเดือนก่อน

    really undurated!

  • @AfzalKhan-dp9zh
    @AfzalKhan-dp9zh 3 หลายเดือนก่อน

    splendid...keep up good work.

  • @kumaranb8702
    @kumaranb8702 3 หลายเดือนก่อน

    Very nice 👍🙂

  • @Anonymous-6598
    @Anonymous-6598 3 หลายเดือนก่อน

    Great video

  • @kamurashev
    @kamurashev 3 หลายเดือนก่อน

    Nice

  • @Pawlo370
    @Pawlo370 3 หลายเดือนก่อน

    Why you have adverbs if you have sponsored video?

    • @Martin-delta
      @Martin-delta 3 หลายเดือนก่อน +1

      What do you mean? “An adverb is a word or an expression that generally modifies a verb, adjective, another adverb”.

    • @DrDeuteron
      @DrDeuteron 3 หลายเดือนก่อน

      @@Martin-deltayou’re kidding right? It’s too deadpan.

    • @Martin-delta
      @Martin-delta 3 หลายเดือนก่อน

      @@DrDeuteron lol no. I was genuinely confused. I just copied the Wikipedia entry for adverb. 🤷‍♀️

  • @neuromorphing9933
    @neuromorphing9933 3 หลายเดือนก่อน +2

    Lame... seen these "tips" 1_000_000 times before....

    • @sridharhisaria
      @sridharhisaria 3 หลายเดือนก่อน +2

      i like the pun here