the code is in belows:
class A(object):
__instance = None
def __new__(cls, *args, **kwargs):
if cls.__instance is None:
cls.__instance = object.__new__(cls)
return cls.__instance
else:
return cls.__instance
def __init__(self, book):
self.book = book
def pr(self):
print(self.book)
if __name__ == "__main__":
b = A("wind")
a = A("good")
print(a is b)
print(a.pr())
print(b.pr())
the result is
True good None good Nonewhy the result is not:
True wind good
where is wrong with the code?
aisbhow shouldpr()return different values?True wind wind,