Return instance name as a string in class function

Viewed 26

I have a class that has the __str__() method. An instance of the class 'a' is created. Is there a way of returning this instance name as a string when i print(a)

class MyClass:
    def __str__(self):
        return self

a = MyClass()
print(a)
0 Answers
Related