+ 1

Python- can someone help me with the logic

Class Geom(object): def __init__(self, h=10, w=10): self.h , self.w=h,w def rectangle (self): rect= self.h*2 + self.w*2 return rect a= Geom(4) print(a.rectangle())

21st Sep 2018, 5:34 AM
AMAN TOMAR
AMAN TOMAR - avatar
5 Answers
+ 1
geom(4) overrides the first parameter h with 4, w stays at the default 10. rect = 4*2 + 10*2 rect = 8 + 20 return 28
21st Sep 2018, 5:41 AM
JME
+ 1
where can't you understand?
21st Sep 2018, 5:54 AM
Flandre Scarlet
Flandre Scarlet - avatar
+ 1
you passed it a value, if you just do a=Geom() it will use both defaults, can also do a = Geom(w=4) to specify which parameter to override, or a = Geom(4,5) to override both
21st Sep 2018, 5:57 AM
JME
0
thanks .can u pls help me understand why does it override
21st Sep 2018, 5:55 AM
AMAN TOMAR
AMAN TOMAR - avatar
0
got it.thank you
21st Sep 2018, 6:03 AM
AMAN TOMAR
AMAN TOMAR - avatar