20 Everyday Tips & Tricks in Python

Sdílet
Vložit
  • čas přidán 4. 07. 2024
  • How's it going everyone? Today we're going to be going over 20 everyday tips and tricks that you can use in your Python scripts!
    ▶ Become job-ready with Python:
    www.indently.io
    ▶ Follow me on Instagram:
    / indentlyreels
    00:00 Learning Python made simple
    00:05 Intro
    0012: Variable swapping
    01:10 Reversing iterables
    01:45 Multiplying strings
    02:40 One line conditions
    03:28 Joining strings
    04:32 Getting values
    05:52 Getting & setting values
    07:19 Counters
    08:37 Specifying a start
    09:37 Dictionary merging
    10:23 Underscore formatting
    11:58 Callable classes
    13:32 Method chaining
    15:07 Formatted list printing
    16:06 Representation
    17:17 Unpacking
    18:37 Quick debugging
    19:31 Rounding
    20:38 String replacement
    21:56 Max & min keys
    25:01 End

Komentáře • 50

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

    "It's cool because there is Bob" 😂

  • @user-zy8ug5pk1q
    @user-zy8ug5pk1q Před 6 dny +4

    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

  • @cefarix
    @cefarix Před 7 dny +4

    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.

  • @rubenvanderark4960
    @rubenvanderark4960 Před 7 dny +9

    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 Před 6 dny +2

      In that case we can use *re.sub*

  • @DrDeuteron
    @DrDeuteron Před 7 dny +3

    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.

  • @syrupthesaiyanturtle
    @syrupthesaiyanturtle Před 2 dny

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

  • @jeffreyphipps1507
    @jeffreyphipps1507 Před 6 dny +1

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

  • @JG-gy3tt
    @JG-gy3tt Před 5 dny

    Great video. My interest was peaked while watching.

  • @mudi2000a
    @mudi2000a Před 7 dny +2

    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 Před 4 dny +1

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

  • @AfzalKhan-dp9zh
    @AfzalKhan-dp9zh Před 7 dny

    splendid...keep up good work.

  • @loverboykimi
    @loverboykimi Před 7 dny

    This is Gold!

  • @anon_y_mousse
    @anon_y_mousse Před 5 dny

    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.

  • @A.A.AGaming1
    @A.A.AGaming1 Před 7 dny +1

    Your content is very useful

  • @troshujin
    @troshujin Před 7 dny

    Yeah another indently vid! :D

  • @Anonymous-6598
    @Anonymous-6598 Před 7 dny

    Great video

  • @laytonjr6601
    @laytonjr6601 Před 7 dny +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 Před 6 dny +1

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

  • @kumaranb8702
    @kumaranb8702 Před 7 dny

    Very nice 👍🙂

  • @christopheanfry2425
    @christopheanfry2425 Před 7 dny

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

    • @novamc7945
      @novamc7945 Před 2 dny

      pretty sure he uses the default

  • @kamurashev
    @kamurashev Před 7 dny

    Nice

  • @richardbennett4365
    @richardbennett4365 Před 6 dny +2

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

  • @theorange6460
    @theorange6460 Před 7 dny +2

    I use these tricks everyday

  • @richardbennett4365
    @richardbennett4365 Před 6 dny

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

  • @user-vt9bp2ei1w
    @user-vt9bp2ei1w Před 7 dny

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

  • @user-ic8ok9cy9e
    @user-ic8ok9cy9e Před 11 hodinami

    what is the difference __str__ and __repr__

  • @luketurner314
    @luketurner314 Před 7 dny

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

  • @richardbennett4365
    @richardbennett4365 Před 6 dny +1

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

  • @nahian2270
    @nahian2270 Před 7 dny

    He made python more simpler

  • @BobChess
    @BobChess Před 7 dny

    I love python

  • @wujublazedman6984
    @wujublazedman6984 Před 7 dny +2

    33 sec ago was wild

  • @lesheq85
    @lesheq85 Před 7 dny +2

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

  • @richardbennett4365
    @richardbennett4365 Před 6 dny

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

  • @vslabs-za
    @vslabs-za Před 7 dny

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

  • @rokaskarabevicius
    @rokaskarabevicius Před 4 dny +1

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

  • @Pawlo370
    @Pawlo370 Před 7 dny

    Why you have adverbs if you have sponsored video?

    • @Martin-delta
      @Martin-delta Před 7 dny +1

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

    • @DrDeuteron
      @DrDeuteron Před 7 dny

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

    • @Martin-delta
      @Martin-delta Před 7 dny

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

  • @neuromorphing9933
    @neuromorphing9933 Před 7 dny +2

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

  • @user-rk2sz2on3d
    @user-rk2sz2on3d Před 7 dny

    really undurated!