Will anyone see my error?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
5th Jul 2021, 12:28 PM
Kajal Kumari
6 Answers
+ 2
#corected code class person: def __init__(self,name,age,city): self.name=name self.age=age self.city=city def say_hi(self): print("hello,my name is",self.name,"i am of ",self.age,"i live at",self.city) p=person('rina',45,'patna') p.say_hi() edit: Slick yes. say_hi(self) : needed instead of say_hi() and arguments to object (already done) it's difficult to explain single error so easily I posted working code ..
5th Jul 2021, 12:49 PM
Jayakrishna 🇮🇳
+ 1
there should only be one __init__ method. all the parameters can go in the one __init__ method Jayakrishna🇮🇳 bruh... he was so close
5th Jul 2021, 12:29 PM
Slick
Slick - avatar
+ 1
Thanks all
5th Jul 2021, 1:29 PM
Kajal Kumari
0
While calling method you need not to Pass self again because python itself takes it as a parameter, that's what your error was saying
5th Jul 2021, 1:30 PM
Sumit Kumar
Sumit Kumar - avatar
- 1
Will u plzz solve this??
5th Jul 2021, 12:48 PM
Kajal Kumari
- 1
class person: def __init__(self,name,age,city): self.name=name self.age=age self.city=city def say_hi(self): print("hello,my name is",self.name,"i am of ",self.age,"i live at",self.city) p=person('rina',34,'patna') p.say_hi() Actually while defining a class method it by default take a general instance which we commonly refer as self, so it needs to be passed while defining method for your class
5th Jul 2021, 1:29 PM
Sumit Kumar
Sumit Kumar - avatar