class learn:
def __init__(self, first_name: str, last_name: str, age: int):
self.first_name = first_name
self.last_name = last_name
self.age = age
def __str__(self, acc):
if isinstance(acc, learn):
return f' My name is {self.first_name} {self.last_name} and I am {self.age}'
raise Exception(f"{acc} is not of class learn ")
acc = learn('Ranjeet', 'Kumar', 22)
print(acc)
TypeError: __str__() missing 1 required positional argument: 'acc'
def __str__(self, acc):
, what do you think theself
part means? What do you think it will refer to? Where do you expect the value foracc
to come from? Also, did you try to research the problem? For example, you could try puttinghow do I write a __str__ method in python
into a search engine. It really is that easy to look things up.