With collections.namedtuple one can make a Point = namedtuple('Point', 'x y')
and set p = Point(2,3)
, and unpack p
using x, y = p
.
Can something similar be done with classes? e.g
class Point:
def __init__(self,x ,y):
self.x = x
self.y = y
p = Point(2,3)
x,y = p
print(f"x: {x}, y: {y}")
>>> x: 2, y: 3
This would result in an error of course, but how can one get the effect of the namedtuple?