Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python dataclass

from dataclasses import dataclass


@dataclass
class Rectangle:
    # Constructor
    height: float
    width: float


@dataclass
class Square(Rectangle):
    # initialization with default value
    side: float = 4

    # post initialize inheritance constructor
    def __post_init__(self):
        super().__init__(self.side, self.side)


sq = Square(height=10, width=2)
print(sq)
# output Square(height=4, width=4, side=4)
Source by codefreelance.net #
 
PREVIOUS NEXT
Tagged: #python #dataclass
ADD COMMENT
Topic
Name
1+4 =