How To Use Dunder Methods In Python Tutorial (Magic Methods)
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!
Пікірлер: 29
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
7 ай бұрын
It's called context manager, like open function
Great ! I had heard of dundermethods but I had no idea where the name came from. Thanks !
Thanks for such short but highly informative videos
I finally understand dunder methods. Thanks sooo much ❤
I am very happy when I see your videos ❤
This is Gold!
nice, thanks
Flet tutorials plz.. I really enjoy by learning it.
Cool 👍
Very nice 🙂❤
@rishiraj2548
7 ай бұрын
🎉
need your pycharm setup
where can i find all the dunder methods? i cant find them in python docs
@marcelo7302
5 ай бұрын
I have the same problem, guess that's why they're magic 😂
What font are you using? The characters combining into one arrow seems interesting
@Nicfallenangel
7 ай бұрын
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
5 ай бұрын
@@Nicfallenangel Works in other IDEs? Like VSCode?
I want to learn python programming language please 🙏 can you teach me
Maybe consider coveirng infix operators. Not super useful at least as far as clean code goes, but certainly a neat trick
@Indently
7 ай бұрын
Thanks for the suggestion, looks super interesting as a trick ahaha, probably will be one of the next shorts
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
7 ай бұрын
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
7 ай бұрын
Has this been explained previously on your channel?
Can we create user magic method?
@Y0annSA
7 ай бұрын
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
7 ай бұрын
I think we should start a petition though to make __banana__ a world standard by Python 3.15
@Y0annSA
7 ай бұрын
@@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
7 ай бұрын
But I really like the single underscore Italic version, because as Python devs we all know what we were trying to do xD