Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Capital City by malykony
class Capital(object):
__instance = None
def __new__(cls, val):
if Capital.__instance is None:
Capital.__instance = object.__new__(cls)
Capital.__instance.__name = val
return Capital.__instance
def name(self):
return Capital.__instance.__name
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
ukraine_capital_1 = Capital("Kyiv")
ukraine_capital_2 = Capital("London")
ukraine_capital_3 = Capital("Marocco")
assert ukraine_capital_2.name() == "Kyiv"
assert ukraine_capital_3.name() == "Kyiv"
assert ukraine_capital_2 is ukraine_capital_1
assert ukraine_capital_3 is ukraine_capital_1
print("Coding complete? Let's try tests!")
May 2, 2020