Skip to content

Instantly share code, notes, and snippets.

@RahulDas-dev
Last active December 18, 2022 16:20
Show Gist options
  • Select an option

  • Save RahulDas-dev/a4f15d5ecef5ad696c18534f0b766b8e to your computer and use it in GitHub Desktop.

Select an option

Save RahulDas-dev/a4f15d5ecef5ad696c18534f0b766b8e to your computer and use it in GitHub Desktop.
Dataclass Example
from dataclasses import dataclass, field
from pprint import pprint
import inspect
@dataclass(frozen=True)
class Dimension:
height: float
width: float
depth: float
@property
def volumn(self):
return self.height *self.width*self.depth
@property
def area(self):
return self.width*self.depth
#pprint(inspect.getmembers(Dimension,inspect.isfunction))
d1 = Dimension(10,25.6,89.6)
d2 = Dimension(width=28.6,depth=19.6,height=50,)
d3 = Dimension(width=25.6,depth=89.6,height=10,)
pprint(d1)
pprint(d2)
pprint(d3)
if (d1==d3):
print(f'{d1} and {d2} are equal')
else:
print(f'{d1} and {d2} are not equal')
print(d1.volumn)
print(d1.area)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment