I have created my own LIFO container class Stack that supports the methods of push, len, pop, and a check on isEmpty. All methods appear to be working in my example calls, except for when I call a created instance of this class(in my example s) I receive a memory location for the created object when I want to see the actual contents of that object.
class Stack:
x = []
def __init__(self, x=None):
if x == None:
self.x = []
else:
self.x = x
def isEmpty(self):
return len(self.x) == 0
def push(self,p):
self.x.append(p)
def pop(self):
return self.x.pop()
def __len__(self):
return(len(self.x))
s = Stack()
s.push('plate 1')
s.push('plate 2')
s.push('plate 3')
print(s)
print(s.isEmpty())
print(len(s))
print(s.pop())
print(s.pop())
print(s.pop())
print(s.isEmpty())
I get the result of running this line print(s) to be <__main__.Stack object at 0x00000000032CD748>t when I would expect and am looking for ['plate 1','plate 2','plate3']
listwould be fine on its own.