First page Back Continue Last page Overview Image

Verbessertes __add__ und __iadd__

def __add__(self, other):

if type(other) == int or type(other) == float:

value = self.convert("m") + other

else:

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 type(other) == int or type(other) == float:

value = self.convert("m") + other

else:

if self.unit == other.unit:

self.value = self.value + other.value

else:

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

return self