+ 1

How can i fetch the value of a variable initialized in Constructor using a class object

Hi All, How can i fetch the value of a variable initialized in Constructor using a class object. PFB the code: class Dog: legs = 4 def __init__(self, name, color): self.name = name self.color = color wings=0 fido = Dog("Fido", "brown") print(fido.wings) Here i want to get the value of variable "wings"

7th Aug 2017, 1:51 PM
Rahul V.Kumar
2 ответов
+ 2
Just put `self.` in front of wings when its being defined. def __init__(self, name, color): self.name = name self.color = color self.wings = 0
7th Aug 2017, 1:56 PM
AgentSmith
0
@Netkos Ent Thank you. It worked.
7th Aug 2017, 4:08 PM
Rahul V.Kumar