+ 3
Why there's an error in printing?
class group: mem=2 def __init__(self,name,age,work): self.name=name self.age=age self.work=work def printd(self): return f"Name is {self.name},age is {self.age} and work is {self.work}" harry=group("Harry",30,"Programer") keshav=group("Keshav",17,"Learner") keshav.mem=3 print(keshav.printd)
5 Respuestas
+ 4
See..
You have given extra indent in printd function Declaration, so its not considered a part of the class.
Now, after correcting this error, call the function printd with parentheses as its a method.
The correct code is as below
class group:
mem=2
def __init__(self,name,age,work):
self.name=name
self.age=age
self.work=work
def printd(self):
return f"Name is {self.name},age is {self.age} and work is {self.work}"
harry=group("Harry",30,"Programer")
keshav=group("Keshav",17,"Learner")
keshav.mem=3
print(keshav.printd())
+ 3
Charitra Agarwal thanks it's working fine now
+ 2
Keshav Kumar
Welcome🤗
+ 1
Anyone here to help?
+ 1
Or I'm just alone ;(