+ 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())
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
+ 1
where can't you understand?
+ 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
0
thanks .can u pls help me understand why does it override
0
got it.thank you