Python's magic methods

  Рет қаралды 12,509

Carberra

Carberra

Күн бұрын

Пікірлер: 12
@zbigniewloboda3393
@zbigniewloboda3393 Жыл бұрын
The front of the editor is to small for handheld devices.
@cn-ml
@cn-ml Жыл бұрын
00:00 Intro 01:30 init 02:36 init_subclass 04:38 str 05:24 repr 06:29 int, float 06:49 hash 07:38 operators (add, ...) 11:00 i-operators (iadd, ...) 12:15 equality operators (eq, ne) 13:40 comparison operators (le, lt, ge, gt) 15:09 contains (in operator) 16:24 getitem, getattr (index operator)
@JorgeEscobarMX
@JorgeEscobarMX 10 ай бұрын
The font is way to small for my phone.
@Carberra
@Carberra 10 ай бұрын
This is an older video; I use a bigger font nowadays.
@Alan910127
@Alan910127 Жыл бұрын
There's an ORM package called SQLModel created by the author of FastAPI, which is built on top of SQL Alchemy and Pydantic, utilized the __init_subclass__ dunder method to distinguish the defined class should be a database table or just or a normal Pydantic model.
@doritorick
@doritorick Жыл бұрын
Hey, great video showcasing those methods! I was wondering, how did you manage to get that beautiful, clean terminal? Mine shows unnecessary paths and details and a bunch of other ugly stuff before actually displaying the output of my program. Perhaps you could make a tutorial on how to clean up the terminal?
@Carberra
@Carberra Жыл бұрын
I have one already! kzbin.info/www/bejne/aoPYeH5prJuAmNU The config I actually use day-to-day is this: github.com/parafoxia/dotfiles/blob/main/.config/starship.toml
@airatvaliullin8420
@airatvaliullin8420 9 ай бұрын
13:19 I think it'd be better to raise a TypeError when trying to compare the object with an object of a different type: from typing import Self def __eq__(self, other: Self) -> bool: if not isinstance(other, self.__class__): raise TypeError(f'The equality operator is not defined between {self.__class__} and {other.__class__} ') return ... # normal logic between two instances of Self This wouldn't let such comparisons (which are almost surely errors) run quietly.
@Carberra
@Carberra 9 ай бұрын
I can certainly see this being preferable in certain situations, but the default behaviour when comparing equity between two non-equal types is to just return False. `return NotImplemented` does indeed do that (I've double checked since making this video), and if you compare, say, and string and an int, you'll get that behaviour.
@airatvaliullin8420
@airatvaliullin8420 9 ай бұрын
@@Carberra hmm, true, I didn't know that... I thought it'd make more sense to throw an exception (like they do with the other comparison operators)
@Carberra
@Carberra 9 ай бұрын
It does definitely make sense from a consistency standpoint to throw an error. But then I spose logically, if two things are different objects, they're not equal so you can easily get an answer. That's my theory why they went for that anyways.
@blackbananapineapple6579
@blackbananapineapple6579 Жыл бұрын
Async TaskGroups are brand new and INSANELY USEFUL
6:39
Carberra
Рет қаралды 10 М.
Metaclasses in 17 minutes
17:29
Carberra
Рет қаралды 5 М.
My MEAN sister annoys me! 😡 Use this gadget #hack
00:24
JOON
Рет қаралды 1,5 МЛН
ЗНАЛИ? ТОЛЬКО ОАЭ 🤫
00:13
Сам себе сушист
Рет қаралды 4,1 МЛН
the balloon deflated while it was flying #tiktok
00:19
Анастасия Тарасова
Рет қаралды 35 МЛН
When to (Not) Use Dunder Methods?
20:37
ArjanCodes
Рет қаралды 30 М.
The COMPLETE guide to Python properties
15:30
Carberra
Рет қаралды 3,9 М.
Itertools is a MUST-KNOW Python module
14:40
Carberra
Рет қаралды 6 М.
Understanding Python: Magic Methods
20:03
Jake Callahan
Рет қаралды 4,5 М.
Special Methods  ||  Python Tutorial  ||  Learn Python Programming
12:23
5 Useful Dunder Methods In Python
16:10
Indently
Рет қаралды 62 М.
3/6 OOP & Classes in Python: Special (dunder/magic) Methods
22:24
Fabio Musanni - Programming Channel
Рет қаралды 1,7 М.
Enums in Python are SIMPLE but POWERFUL
11:47
Carberra
Рет қаралды 7 М.
Are metaclasses the HARDEST thing in Python?
20:41
Carberra
Рет қаралды 4,8 М.
Functools is one of the MOST USEFUL Python modules
13:37
Carberra
Рет қаралды 34 М.