How To Use Dunder Methods In Python Tutorial (Magic Methods)

Поделиться
HTML-код
  • Опубликовано: 2 июн 2024
  • In this video I will be teaching you all the essentials you need to know when it comes to using dunder methods in Python.
    ▶ Become job-ready with Python:
    www.indently.io
    ▶ Follow me on Instagram:
    / indentlyreels
    00:00 Introduction to dunder methods
    00:34 What do we use dunder methods for?
    01:34 How to use a dunder method
    03:00 What about other dunder methods?
    04:33 Exploring the dunder methods
    05:53 Do you have any thoughts on dunder methods? 06:29 That’s all for this time folks!

Комментарии • 27

  • @Exvixcity
    @Exvixcity 5 месяцев назад +30

    def __enter__(self) and def __exit__(self) are really useful too.
    It allows you to use the with() keyword with your class.
    __enter__ defines what happens as soon as the line with the "with" keyword runs.
    You don't need to do anything special here, just make sure you "return self"
    __exit___ defines what happens as soon as the scope changes or there's no more code left to run. Just clean up and/or close files, active connections.etc

    • @MeHdi.fz28
      @MeHdi.fz28 5 месяцев назад +4

      It's called context manager, like open function

  • @Lord_Shan
    @Lord_Shan 5 месяцев назад

    Thanks for such short but highly informative videos

  • @fusebox9725
    @fusebox9725 5 месяцев назад

    I finally understand dunder methods. Thanks sooo much ❤

  • @Naruto.Hinata-clips
    @Naruto.Hinata-clips 5 месяцев назад

    I am very happy when I see your videos ❤

  • @loverboykimi
    @loverboykimi 5 месяцев назад

    This is Gold!

  • @ufukyarsan2149
    @ufukyarsan2149 5 месяцев назад

    nice, thanks

  • @gauravsoni4025
    @gauravsoni4025 5 месяцев назад

    Flet tutorials plz.. I really enjoy by learning it.

  • @kumaranb8702
    @kumaranb8702 5 месяцев назад +2

    Very nice 🙂❤

  • @miguelvasquez9849
    @miguelvasquez9849 5 месяцев назад +4

    where can i find all the dunder methods? i cant find them in python docs

    • @marcelo7302
      @marcelo7302 3 месяца назад +1

      I have the same problem, guess that's why they're magic 😂

  • @krzysiekkrzysiek9059
    @krzysiekkrzysiek9059 5 месяцев назад

    Cool 👍

  • @JopeliH
    @JopeliH 5 месяцев назад +1

    What font are you using? The characters combining into one arrow seems interesting

    • @Nicfallenangel
      @Nicfallenangel 5 месяцев назад

      I'm not sure exactly what font he is using, but it's probably a Nerd Font with "font ligatures" turned on. Ligatures is the feature that combines the characters. I use a font called FiraCode that has support for ligatures and it looks weird now any time I'm using some other system that doesn't support them.

    • @JakkeJakobsen
      @JakkeJakobsen 3 месяца назад

      ​@@Nicfallenangel Works in other IDEs? Like VSCode?

  • @kingfunny4821
    @kingfunny4821 5 месяцев назад

    If I have an application made in Python and a copy is given to a person in America and a copy is given to a person in Italy, how can I make the two people exchange messages with each other?
    Can you give information about this?

    • @Indently
      @Indently  5 месяцев назад

      If you're talking about creating a chat app, you need to look into writing code that runs a server that both of you can connect to. One of you will have to run the server, but then anyone can connect to it.

    • @kingfunny4821
      @kingfunny4821 5 месяцев назад

      Has this been explained previously on your channel?

  • @danielagu4309
    @danielagu4309 5 месяцев назад

    I want to learn python programming language please 🙏 can you teach me

  • @celestialowl8865
    @celestialowl8865 5 месяцев назад

    Maybe consider coveirng infix operators. Not super useful at least as far as clean code goes, but certainly a neat trick

    • @Indently
      @Indently  5 месяцев назад

      Thanks for the suggestion, looks super interesting as a trick ahaha, probably will be one of the next shorts

  • @devabdul
    @devabdul 5 месяцев назад

    Can we create user magic method?

    • @Y0annSA
      @Y0annSA 5 месяцев назад +3

      You technically can define a method named __banana__​ (for example), Python doesn't forbid it, but it wouldn't be "magic".
      Standard dunder methods are methods that Python automatically calls under specific situations. Since Python wasn't programmed to use __banana__​ in any way, it wouldn't have any effect unless you call it explicitly. It's just a normal method with bad naming convention.
      You would have to fork and develop your own version of Python to create a new magic method

    • @Indently
      @Indently  5 месяцев назад +5

      I think we should start a petition though to make __banana__ a world standard by Python 3.15

    • @Y0annSA
      @Y0annSA 5 месяцев назад

      @@Indently I just found out that writing dunder methods in youtube comments is really annoying since it really wants to make them italic (and removing a pair of underscores in the process). But I found a little cheat by writing a zero-width space immediately after (still not very convenient to find and copy one) (or you could add an extra pair of underscores and accept that it's italic)

    • @Indently
      @Indently  5 месяцев назад

      But I really like the single underscore Italic version, because as Python devs we all know what we were trying to do xD