Python tricks: Using magic (dunder) functions to create list-like objects

  Рет қаралды 16,952

Sebastiaan Mathôt

Sebastiaan Mathôt

Күн бұрын

(For more, visit pythontutorial... !) In this video I demonstrate how you can use magic functions, sometimes called dunder (double-underscore) functions, to support special list-like syntax in your own objects. Specifically, I will demonstrate __len__(), __contains__(), and __getitem__().

Пікірлер: 36
@theawesomegamer123
@theawesomegamer123 4 жыл бұрын
1:30 "Whenever we take a look at a member from the ASAP mob, that member goes solo, because as soon as a member gets a little bit of attention, he goes solo" I laughed so hard when he said this 😂😂
@jsonhub4082
@jsonhub4082 4 жыл бұрын
thx for such infos , good work, BTW this is the third video YT that i've seen about dunder and it's the BEST ONE.
@micahbeckman4442
@micahbeckman4442 4 жыл бұрын
I've seen a lot of python tutorials - yours are the best.
4 жыл бұрын
You probably say that to all the Python KZbinrs ;-)
@micahbeckman4442
@micahbeckman4442 4 жыл бұрын
What other Python KZbinrs? :)
@pilaramonkgogimoshebashebi2371
@pilaramonkgogimoshebashebi2371 6 жыл бұрын
8:00 "If A$AP Sebbie, thats me. Thats my A$AP mob name..." 😂...............😂 That deserves a double like. Good Tutorial.
@debvdo
@debvdo 6 жыл бұрын
Good video. I liked how you return a generator object from a call to __iter__(), using yield. It works as an iterator.
@BigOlKnothead
@BigOlKnothead 9 күн бұрын
The pure depth of actually insightful and useful and unrepetitive conprehensively exhaustive full wealth of the correct information makes you the best code writing creator by huge margins. So many others give the most vagueried minimum of information that often leave the viewer at the end with more questions than the video provided s
@ibekwevictor1158
@ibekwevictor1158 2 жыл бұрын
Thanks for the Tutorial ... I appreciate your work .... Bringing hip hop vibes in python 👍💪
@andyd568
@andyd568 5 жыл бұрын
Sebastiaan is the OG of programming. Great vids.
@yt-1161
@yt-1161 2 жыл бұрын
@11:10 when you write return member in self._members Which function does the python use to check whether the member is "in" the list?
@min2MAXdances
@min2MAXdances 4 жыл бұрын
this was a very helpful straightforward tutorial!
@SebastianSanchez65
@SebastianSanchez65 4 жыл бұрын
great video in dunders!
@UniBreakfast
@UniBreakfast 6 жыл бұрын
No __next__? Also this __iter__ gives members in reverse order. Is it supposed to do that?
6 жыл бұрын
+Михаил Нинин The __next__() function is only necessary when you implement iteration through a separate iterator class, rather than through a generator function as done here (in which case yield serves the same purpose). But you're right about the order: it would've been more elegant to do a pop (0)!
@sheikhakbar2067
@sheikhakbar2067 3 жыл бұрын
Beautiful!
@surajchopade6735
@surajchopade6735 6 жыл бұрын
Thanks for such amazing video
@abhayagarwal5097
@abhayagarwal5097 4 жыл бұрын
Great work man,thks
@marcelangulo510
@marcelangulo510 4 жыл бұрын
Excelente video
@ramstein74
@ramstein74 6 жыл бұрын
Great vid Can you suggest a python book ?
6 жыл бұрын
Thanks! I generally recommend the Python track on CodeAcademy for beginners (www.codecademy.com/learn/learn-python). Or, if you prefer a book format, A Byte of Python (python.swaroopch.com/). For more advanced Pythonistas, I think watching KZbin tutorials about specific issues is a good way to learn as well.
@mainsequence1055
@mainsequence1055 5 жыл бұрын
"Automate the Boring Stuff in Python" is also a great book.
@SS-pz8md
@SS-pz8md 3 жыл бұрын
@ thanks
@TechieGuy82
@TechieGuy82 3 жыл бұрын
Sublime!
@experimentalhypothesis1137
@experimentalhypothesis1137 4 жыл бұрын
interesting video
@dontbetoxic4387
@dontbetoxic4387 3 жыл бұрын
How are ur sunglasses called?? Pls answer
3 жыл бұрын
My sunglasses prefer to remain anonymous ;-)
@dontbetoxic4387
@dontbetoxic4387 3 жыл бұрын
@ :(
@blenderremastered9959
@blenderremastered9959 4 жыл бұрын
programmer elevated to gagster still Sebastiaan Mathôt.
@arryhere
@arryhere Жыл бұрын
single _ is protected , double __ is private
@dillip4572
@dillip4572 4 жыл бұрын
You rock :)
@veziop
@veziop 2 жыл бұрын
goes solo, hilarious
@PaulaJBean
@PaulaJBean 6 жыл бұрын
een ___getitem___ die als side-effect het muteren van de datastructuur heeft? Daar gaan je gebruikers van opkijken. Je schendt daarmee het *principle of least astonishment* , en.wikipedia.org/wiki/Principle_of_least_astonishment
6 жыл бұрын
+Paula J. Bean Dat is een goed punt.
@jamil4322
@jamil4322 5 жыл бұрын
but the x was false sir
Python tricks: properties, staticmethods, and classmethods
12:39
Sebastiaan Mathôt
Рет қаралды 43 М.
A simple explanation of super() in Python
15:02
Sebastiaan Mathôt
Рет қаралды 47 М.
Секрет фокусника! #shorts
00:15
Роман Magic
Рет қаралды 117 МЛН
Самое неинтересное видео
00:32
Miracle
Рет қаралды 2,7 МЛН
Being Competent With Coding Is More Fun
11:13
TheVimeagen
Рет қаралды 55 М.
Python tricks: Demystifying async, await, and asyncio
15:59
Sebastiaan Mathôt
Рет қаралды 94 М.
Python dataclasses will save you HOURS, also featuring attrs
8:50
Profiling and optimizing your Python code | Python tricks
17:11
Sebastiaan Mathôt
Рет қаралды 71 М.
Python tricks: All there is to know about Exceptions
18:12
Sebastiaan Mathôt
Рет қаралды 18 М.
Principles of Beautiful Figures for Research Papers
1:01:14
ChuScience
Рет қаралды 2,3 М.
Object-Oriented Programming is Bad
44:35
Brian Will
Рет қаралды 2,3 МЛН
Pydantic Tutorial • Solving Python's Biggest Problem
11:07
pixegami
Рет қаралды 271 М.
Python tricks: Type hints and static type checking
14:15
Sebastiaan Mathôt
Рет қаралды 21 М.
Python Decorators in 15 Minutes
15:14
Kite
Рет қаралды 442 М.