0

repr method in python

Can anyone explain what is __repr__ and when and how to use it? I can't understand nothing about it.

26th Oct 2018, 4:37 PM
Edgar Tomeyan
Edgar Tomeyan - avatar
2 Respostas
+ 4
class a: def __str__(self): return 'a' def __repr__(self): return 'A' print(a()) #a print(repr(a())) #A print(str(a())) #a >>> class a: ... def __repr__(self): return 'A' ... >>> a() A
26th Oct 2018, 7:33 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 4
__str__ is called when you print a variable __repr__ is called in interactive mode
26th Oct 2018, 7:36 PM
Mert Yazıcı
Mert Yazıcı - avatar