PYTHON МАГИЧЕСКИЕ МЕТОДЫ: __STR__ + __REPR__

preview_player
Показать описание
В этом ролике быстро и доступно рассказываю что такое и зачем нужны магические методы __repr__ и __str__

Поддержать:

#ityoutubers #ityoutubersru
Рекомендации по теме
Комментарии
Автор

Очень полезная информация и хорошая подача материала)

optikrus
Автор

заранее лайк колокольчик комент поставил

ХалилМаденбай
Автор

ну, то есть штатно лучше __repr__ использовать? спасибо за видео

sergey_avargin
Автор

Подскажите пожалуйста, как он закомментировал блок кода шарпом?

gladgalakas
Автор

Выдержка из документации:

object.__repr__(self)
Called by the repr() built-in function to compute the “official” string representation of an object. If at all possible, this should look like a valid Python expression that could be used to recreate an object with the same value (given an appropriate environment). If this is not possible, a string of the form <...some useful description...> should be returned. The return value must be a string object. If a class defines __repr__() but not __str__(), then __repr__() is also used when an “informal” string representation of instances of that class is required.

This is typically used for debugging, so it is important that the representation is information-rich and unambiguous.

Если я правильно понимаю фразу If at all possible, this should look like a valid Python expression that could be used to recreate an object with the same value, то в идеале репр в твоем случае должен быть таким: CustomClass(field1=1, field2=2)

MrLotrus