0
Will anyone see my error??
6 Respostas
+ 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 ..
+ 1
there should only be one __init__ method.
all the parameters can go in the one __init__ method
Jayakrishna🇮🇳 bruh... he was so close
+ 1
Thanks all
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
- 1
Will u plzz solve this??
- 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