+ 1

Why it is saying self not defined...why it won't print value of name

class Wolf: def __init__(self, name, color): self.name = name self.color = color def bark(self): print("Grr...") class Dog(Wolf): def bark(self): print("Woof") husky = Dog("Max", "grey") husky.bark() print(self.name)

25th Feb 2020, 5:42 AM
Sai Deepika Kathiri
Sai Deepika Kathiri - avatar
2 odpowiedzi
+ 2
In your last line, your code doesn't know what self is, because it is not inside a class. Instead, try to print husky.name
25th Feb 2020, 5:45 AM
coddy
coddy - avatar
+ 1
Ok tq
25th Feb 2020, 5:45 AM
Sai Deepika Kathiri
Sai Deepika Kathiri - avatar