[Tutor] Concept related to python classes
Manprit Singh
manpritsinghece at gmail.com
Tue Sep 8 03:37:05 EDT 2020
Dear Sir,
Now i am writing a thankyou email for all of you :
Specially to Alan sir , he expressed his straightforward disagreement with
my ideas , when i was wrong .
Secondarily to Mats Wichmann & boB Stepp & Richard Damon, the discussion
between them helped me to learn something.
I am basically an Electronics Engineer with approx 10 years experience in
the electronics industry and with no computer programming background , and
have started learning Python some 4 to 5 months back. Upon finding a
word @property in one of the recent mails, I started reading about property
and then implemented it with a little understanding and luckily wrote a
program for the first time with a quite lengthy and inefficient code , but
glad that you all mademe to learn about @property.
At last now I have written a code with the help of all of you that seems to
be quiet short and easy., and is quite convincing to me .Code is given
below:
class Triangle:
def __init__(self, x, y, z):
self.resize(x, y, z)
@property
def area(self):
s = (self.a + self.b + self.c) / 2
return (s * (s - self.a) * (s - self.b) * (s - self.c))**0.5
def resize(self, a, b, c):
self.a = a
self.b = b
self.c = c
tri = Triangle(3, 4, 5)
print(tri.area)
tri.resize(4, 4, 5)
print(tri.area)
The output is:
6.0
7.806247497997997
Regards
Manprit Singh
More information about the Tutor
mailing list