Well there are several ways You could go about creating something like this, but I'd stick with a list
. There's no reason to over think it.
I will not be appending anything to the list, and the size is fixed at 2, it feels like a tuple may be a better representation of what the object actually is.
No. List do not have to change size. List can stay a constant size through your entire program. And the list has the distinct advantage, that it supports item assignment.
You could also consider looking into a collections.namedtuple
if your looking for a light weight solution to @kabanus's. In fact, the official Python documentation of namedtuple
shows an example with namedtuple
using points:
>>> # Basic example
>>> Point = namedtuple('Point', ['x', 'y'])
>>> p = Point(11, y=22) # instantiate with positional or keyword arguments
>>> p[0] + p[1] # indexable like the plain tuple (11, 22)
33
>>> x, y = p # unpack like a regular tuple
>>> x, y
(11, 22)
>>> p.x + p.y # fields also accessible by name
33
>>> p # readable __repr__ with a name=value style
Point(x=11, y=22)