+ 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"
2 Respostas
+ 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
0
@Netkos Ent
Thank you.
It worked.