If we define __str__
method in a class:
class Point():
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self, key):
return '{}, {}'.format(self.x, self.y)
We will be able to define how to convert the object to the str
class (into a string):
a = Point(1, 1)
b = str(a)
print(b)
I know that we can define the string representation of a custom-defined object, but how do we define the list —more precisely, tuple— representation of an object?