How to convert an custom class object to a tuple in Python? [closed]
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 3 years ago . 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) So we can convert its object to str immediately: a = Point(1, 1) b = str(a) print(b) But as far as I know, there is not such __tuple__