#dunder — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #dunder, aggregated by home.social.
-
As with any convention, it depends somewhat on opinion. My take:
double-underscore is for Python-provided methods that you want to override, like __mul__ or __getitem__. Not for adding your own unrelated methods; if you want those to be "private", use single underscores.
Python may add new special methods in future, and if they collide with a dunder name you've used for your own method, you could get serious breakage.
-
As with any convention, it depends somewhat on opinion. My take:
double-underscore is for Python-provided methods that you want to override, like __mul__ or __getitem__. Not for adding your own unrelated methods; if you want those to be "private", use single underscores.
Python may add new special methods in future, and if they collide with a dunder name you've used for your own method, you could get serious breakage.
-
Атрибут или Dunder-метод slots в Python. Что нужно о нём знать?
Всем привет! Меня зовут Дима. Я являюсь Backend Python Developer'ом. Сегодня расскажу Вам про «волшебный» инструмент __slots__ в Python.
https://habr.com/ru/articles/884052/
#python #slots #__slots__ #dunder #dunder_methods #class #dataclass