# Python 3
class Point(tuple):
def __init__(self, x, y):
super().__init__((x, y))
Point(2, 3)
would result in
TypeError: tuple() takes at most 1 argument (2 given)
Why? What should I do instead?
# Python 3
class Point(tuple):
def __init__(self, x, y):
super().__init__((x, y))
Point(2, 3)
would result in
TypeError: tuple() takes at most 1 argument (2 given)
Why? What should I do instead?
tuple
is an immutable type. It's already created and immutable before__init__
is even called. That is why this doesn't work.If you really want to subclass a tuple, use
__new__
.