实例代码
class Stack():
def __init__(self, initstack):
self.initstack = initstack
def in_stack(self, number):
# self.number = number
self.initstack.append(number)
print('Now,the stack is %s.' % str(self.initstack))
def out_stack(self):
print('The pop number is %d.' % self.initstack.pop())
print('Now,the stack is %s.' % str(self.initstack))
def top_stack(self):
print('The top number in stack is %d.' %self.initstack[-1])
def length_stack(self):
print('The length of the stack is %d.' % len(self.initstack))
def isnull_stack(self):
if len(self.initstack) == 0:
print('Stack Is Null.')
else:
print('Stack Is Not Null.')
P1 = Stack([10, 20])
P1.in_stack(5)
P1.length_stack()
P1.out_stack()
P1.top_stack()
P1.isnull_stack()