Nov-09-2020, 02:11 PM
(Nov-09-2020, 01:57 PM)buran Wrote:class Fabric: def __init__(self, humans): self.Body = humans def set_eyes(self, value) self.Body.top.eyes = value print(self.Body.top.eyes)thenfabric.set_eyes(4)
.
you need to useself
, notfabric
.self
is the instance, which is passed automatically. But this is anti-pattern in python. Normally we don't need need setters and getters just to modify a property. We will dofabric.Body.top.eyes = 4
outside the class, without the need to defineFabric.set_eyes()
method.
Thank you, now it makes sense! I will read more about this "anti-pattern in python."