First page Back Continue Last page Overview Image

Length Class, Implementierung, 2

def __add__(self, other):

if self.unit == other.unit:

value = self.value + other.value

else:

value = self.value + other.convert(self.unit)

return Length(value, self.unit)

def __iadd__(self, other):

if self.unit == other.unit:

self.value = self.value + other.value

else:

self.value = self.value + other.convert(self.unit)

return self

def __str__(self):

return str(self.value) + " " + self.unit

def __repr__(self):

return "Length(" + str(self.value) +", '" + self.unit + "')"