Home >Backend Development >Python Tutorial >Python栈类实例分析

Python栈类实例分析

WBOY
WBOYOriginal
2016-06-06 11:18:451538browse

本文实例讲述了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程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn