This is a small code in which I have a planets class, and I want to know which was the last planet created.
class Planeta:
ult=''
def __init__(self, nombre):
self.nombre = nombre
self.ult = nombre #the last
print(self.nombre, 'construido')
def last(self):
print('Ultimo constriuido:',self.ult) #print the last
So I create the planets
urano = Planeta('Urano')
neptuno = Planeta('Neptuno')
pluton = Planeta('pluton')
Then I want to know which was the last one created, so I call the method
urano.last()
But the output of the code is
Ultimo constriuido: Urano
When actually the last planet built is Pluto, I want the output to be
Ultimo constriuido: Pluton
I think I understand why this happens, I understand that if I command to call the last()
method, the output is because at that moment that was the last.
But then how do I make the output as I want?