how to return in an __init__ method code example

Example 1: explicit return in __init_

class Rectangle(object):
    def __init__(self, width, height):
        self.width = width
        self.height = height
        self._area = width * height

    @property
    # moved the logic for returning area to a separate method
    def area(self):
        return self._area

Example 2: explicit return in __init_

class Rectangle:
    def __init__(self, width, height):
        self.width = width
        self.height = height
        self.area = width * height
        # return statement removed from here

Tags:

Misc Example