#########类属性示例代码:
class CC:
count = 0
def __init__(self):
CC.count += 1
def __del__(self):
CC.count -= 1
##########模拟栈
class Stack:
def __init__(self, start=[]):
self.stack = []
for each in start:
self.push(each)
def isEmpty(self):
return not self.stack
def push(self, obj):
self.stack.append(obj)
def pop(self):
if not self.stack: #增加程序的强壮性
print('警告:栈为空!')
else:
return self.stack.pop()
def top(self):
if not self.stack:
print('警告:栈为空!')
else:
return self.stack[-1]
def bottom(self):
if not self.stack:
print('警告:栈为空!')
else:
return self.stack[0]
类属性和栈模拟代码
最新推荐文章于 2022-05-16 11:17:25 发布