in the: Lesson
What is the use of the dunder __repr__
?
class Employee():
def __init__(self, name):
self.name = name
def __repr__(self):
return self.name
argus = Employee("Argus Filch")
print(argus)
# prints "Argus Filch"
Only, that I can access the object attributes directly, after the object initiation?
instead, I can use:
either:
def repr(self):
return self.name.
and then, call outside the class:
print(argus.repr())
else:
print(argus.name)