【发布时间】:2016-06-29 11:16:56
【问题描述】:
如何反转包含 def view(self) 的字符串的列表,因为使用 reversed() 我得到一个错误,它不能用字符串完成。有什么帮助吗?
class Stack():
def __init__(self):
self.stack = []
def view(self):
for x in reversed(self.stack):
print(self.stack[x])
def push(self):
item = input("Please enter the item you wish to add to the stack: ")
self.stack.append(item)
def pop(self):
item = self.stack.pop(-1)
print("You just removed item: {0}".format(item))
stack = Stack()
【问题讨论】:
-
有什么理由在
view中没有简单的print(x)?
标签: python-3.x