why am I getting an error? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

why am I getting an error?

class Person: def __init__(self, name, age): self.name = name self.age = age def eatndrink(self): print('eat food and drink water', self.name, self.age) class Car: def hascar(self): print('I have a beautiful car') print(self.age) p = Person('aa', 56) Car.hascar() If the run the above code I am getting typeerror - Car.hascar() missing 1 required positional argument:self

23rd Aug 2022, 5:34 AM
Levi
Levi - avatar
3 Answers
0
Jay Matthews In this code I am trying to access the Person class instance variables inside Car class
23rd Aug 2022, 6:01 AM
Levi
Levi - avatar
0
Jay Matthews May I know the why am I getting the type error in the code
23rd Aug 2022, 6:23 AM
Levi
Levi - avatar