Easy Syntax in Python : __STR__ Vs __REPR__ Functions

preview_player
Показать описание
In this 3 minutes video , you will understand the main difference between the __str__ and the __repr__ built-in Python methods.

Both the str() and repr() functions are used for string representation of a Python object, in Python version 2 you had to use print followed by str or repr, but in Python 3 you can directly use str() or repr().
the __str__ and __repr__ are methods to be used inside a user defined class, while the str() and repr() functions can be used outside classes for conversion purposes.

p.s. : For simplicity, I used function and method interchangeably but to be precise __str__ and __repr__ are ,in fact, methods.

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

Did u know u are good
Well you are exceptional ❤

Sharafuna
Автор

Amazing! summing it up in 3 mins, you are a genius sir.

MHF-gosd
Автор

What about “str” why outputs as ‘str’, [1] as [1] and so on.
What methods are called implicitly?

chhoukdying