|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
想请问这个self.push的意思是不是表示假如我新建一个名叫aa的实例对象,那么这个self.push(x)其实也就是aa.push(x)么?可以这样理解么?
- class Stack:
- def __init__(self, start=[]):
- self.stack = []
- [color=Red]for x in start:
- self.push(x)[/color]
- 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]
复制代码
是的。在类方法中,self 参数可以理解为类的实例。
|
|