Тёмный
No video :(

Python's magic methods 

Carberra
Подписаться 19 тыс.
Просмотров 12 тыс.
50% 1

Who wouldn't want to sprinkle a little magic onto their code? Well, with Python's magic methods, you can! You can even get some neat functionality out of it too.
-
If you enjoy my content, consider supporting me on Patreon or becoming a member!
patreon.carber...
join.carberra.xyz
If you need help with anything, feel free to join the Discord server:
discord.carber...
I get a lot of people asking, so here's my Visual Studio Code setup!
• My Visual Studio Code ...
-
If you have any questions, don't hesitate to ask in the comments! I'll try and answer as soon as I can, providing someone else hasn't already done so.
#python #coding #howto

Опубликовано:

 

29 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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)
@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.
@JorgeEscobarMX
@JorgeEscobarMX 7 месяцев назад
The font is way to small for my phone.
@Carberra
@Carberra 7 месяцев назад
This is an older video; I use a bigger font nowadays.
@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! ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-4RuGK3w6Mbs.html The config I actually use day-to-day is this: github.com/parafoxia/dotfiles/blob/main/.config/starship.toml
@airatvaliullin8420
@airatvaliullin8420 7 месяцев назад
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 7 месяцев назад
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 7 месяцев назад
@@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 7 месяцев назад
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
Metaclasses in 17 minutes
17:29
Просмотров 4,6 тыс.
Bilasizmi?
00:12
Просмотров 397 тыс.
When to (Not) Use Dunder Methods?
20:37
Просмотров 29 тыс.
5 Useful Dunder Methods In Python
16:10
Просмотров 58 тыс.
Are descriptors the most MISUNDERSTOOD part of Python?
16:42
Functools is one of the MOST USEFUL Python modules
13:37
Python MAGIC METHODS are easy! 🌟
13:36
Просмотров 5 тыс.
This Is Why Python Data Classes Are Awesome
22:19
Просмотров 802 тыс.
Itertools is a MUST-KNOW Python module
14:40
Просмотров 5 тыс.
Generics: The most intimidating TypeScript feature
18:19
25 nooby Python habits you need to ditch
9:12
Просмотров 1,7 млн