تابع ()rper یک رشتهٔ نمایشی/رسمی از یک شیء رو برمیگردونه. برای مثال:
class Student (object):
def __init__ (self, first_name, last_name, age):
self.first_name = first_name
self.last_name = last_name
self.age = age
self.full_name = "{} {}".format(self.first_name, self.last_name)
def __repr__ (self):
return "Student<name:{}, age:{}>".format(self.full_name, self.age)
def __str__(self):
return self.full_name
student = Student("John", "Doe", 18)
repr(student) # => Student<name:John Doe, age:18>
str(student) # => John Doe
print(student) # => John Doe