|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
class Stack:
def __init__(self, start=[]): #此处start=[]已经赋了初值,为什么结果报错,说start没有找到呢
self.stack = []
for x in start:
self.push(x)
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]
a=Stack(start)
print(a.stack)
=== RESTART: C:/Users/admin/AppData/Local/Programs/Python/Python38/39.栈的操作.py ==
Traceback (most recent call last):
File "C:/Users/admin/AppData/Local/Programs/Python/Python38/39.栈的操作.py", line 32, in <module>
a=Stack(start)
NameError: name 'start' is not defined |
|