我在 python 中实现了一个堆栈,但是 "push" 方法不起作用

I implement a stack in python, however the "push" method doesn't work

我还是新手python,所以在练习实现栈,不明白为什么push方法不行。我的代码如下:

class Stack:

    def __init__(self):
        self.top = None
        self.size = 0

    def isEmpty(self):
        return self.top == None
    
    def push(self, value):
        node = Node(value, self.top)        
        self.top = node
        self.size += 1

    def pop(self):
        assert not self.isEmpty, "Error: The stack is empty"
        node = self.top
        self.top = self.top.next
        return node.value

class Node:

    def __init__(self, value, link):
        self.value = value
        self.next = link
    

def main():
    
    stack = Stack()
    assert stack.isEmpty, "--> Error: isEmpty"
    stack.push(1)
    assert not stack.isEmpty, "--> Error: not isEmpty"  
    print(stack.pop())  

if __name__ == "__main__":
    main()

这是出口:

文件“c:”,第 33 行,在 main 中 断言不是 stack.isEmpty,“--> 错误:不是 isEmpty”
AssertionError: --> 错误:不是 isEmpty

stack.isEmpty是一个函数,而stack.isEmpty()是一个函数调用(返回一个布尔值)。

编辑:如果您想要一个属性 isEmpty,请在 __init__() 中声明一个,并确保在对象发生更改时更新它。这样你就可以引用 stack.isEmpty 而无需调用函数。这更多是个人喜好。