我正在尝试为堆栈实现这些函数:push(S)、isEmpty(S)、top(S)、nextToTop(S)。它说语法错误。如何测试
S= [1, 5, 13, 21]
def push(S):
return S
def isEmpty(S):
if S = []:
print ("Empty String")
else:
print ("String is not empty")
def Top(S):
if S = []:
print ("Empty String")
else:
return S[0]
def nextToTop(S):
if S = []:
print ("String is not empty")
else:
return S[1]
print(push(S))
print(isEmpty(S))
print(Top(S))
print(nextToTop(S))
S = []
是赋值运算符,其中as==
是conditional equal to
运算符。因此,检查空列表的if
条件应该类似于if S == []
同样的行为也可以通过简单的操作来实现:
相关问题 更多 >
编程相关推荐