Telegram Group & Telegram Channel
Разница между __str__ и __repr__

Оба магических метода __str__ и __repr__ используются для получения строкового представления объекта. Давайте разберемся, в чем же собственно разница между ними.

Метод __str__ используется для создания вывода для конечного пользователя, а __repr__ в основном используется для отладки и разработки. Другими словами, цель __repr__ – быть однозначным, а __str__ – читабельным.

Функция print() и встроенная функция str() используют метод __str__ для отображения строкового представления объекта, а вот встроенная функция repr() использует для этого метод __repr__.

#классы #str #repr



tg-me.com/python_academy/847
Create:
Last Update:

Разница между __str__ и __repr__

Оба магических метода __str__ и __repr__ используются для получения строкового представления объекта. Давайте разберемся, в чем же собственно разница между ними.

Метод __str__ используется для создания вывода для конечного пользователя, а __repr__ в основном используется для отладки и разработки. Другими словами, цель __repr__ – быть однозначным, а __str__ – читабельным.

Функция print() и встроенная функция str() используют метод __str__ для отображения строкового представления объекта, а вот встроенная функция repr() использует для этого метод __repr__.

#классы #str #repr

BY Python Academy




Share with your friend now:
tg-me.com/python_academy/847

View MORE
Open in Telegram


Python Academy Telegram | DID YOU KNOW?

Date: |

A project of our size needs at least a few hundred million dollars per year to keep going,” Mr. Durov wrote in his public channel on Telegram late last year. “While doing that, we will remain independent and stay true to our values, redefining how a tech company should operate.

Telegram and Signal Havens for Right-Wing Extremists

Since the violent storming of Capitol Hill and subsequent ban of former U.S. President Donald Trump from Facebook and Twitter, the removal of Parler from Amazon’s servers, and the de-platforming of incendiary right-wing content, messaging services Telegram and Signal have seen a deluge of new users. In January alone, Telegram reported 90 million new accounts. Its founder, Pavel Durov, described this as “the largest digital migration in human history.” Signal reportedly doubled its user base to 40 million people and became the most downloaded app in 70 countries. The two services rely on encryption to protect the privacy of user communication, which has made them popular with protesters seeking to conceal their identities against repressive governments in places like Belarus, Hong Kong, and Iran. But the same encryption technology has also made them a favored communication tool for criminals and terrorist groups, including al Qaeda and the Islamic State.

Python Academy from us


Telegram Python Academy
FROM USA