当前位置:主页 > 软件编程 > Python代码 >

Python栈类实例分析

时间:2021-03-29 09:41:04 | 栏目:Python代码 | 点击:

本文实例讲述了python栈类。分享给大家供大家参考。具体如下:

class Path: #a list used like a stack
    def __init__(self):
        self.P = []
    def push(self,t):
        self.P.append(t)
    def pop(self):
        return self.P.pop()
    def top(self):
        return self.P[-1]
    def remove(self):
        self.P.pop(0)
    def isEmpty(self):
        return (len(self.P)==0)
    def printPath(self):
        print self.P

希望本文所述对大家的Python程序设计有所帮助。

您可能感兴趣的文章:

相关文章