+ 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)

2nd Sep 2020, 8:23 AM
‎Keshav
‎Keshav - avatar
5 Answers
+ 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())
2nd Sep 2020, 8:34 AM
Charitra
Charitra - avatar
+ 3
Charitra Agarwal thanks it's working fine now
2nd Sep 2020, 8:36 AM
‎Keshav
‎Keshav - avatar
+ 2
Keshav Kumar WelcomeđŸ€—
2nd Sep 2020, 8:38 AM
Charitra
Charitra - avatar
+ 1
Anyone here to help?
2nd Sep 2020, 8:29 AM
‎Keshav
‎Keshav - avatar
+ 1
Or I'm just alone ;(
2nd Sep 2020, 8:29 AM
‎Keshav
‎Keshav - avatar