小甲鱼(鱼C)课后作业代码 39讲

版权声明:转载请标明出处 https://blog.csdn.net/AnimateX/article/details/80309884

小甲鱼 039 动手做一做

# -*- coding: utf-8 -*-
'''
Created on Mon May 14  2018

@author: 
'''

This one

class Varible:
    nums = 0
    def __init__(self):
        Varible.nums += 1

    def __del__(self):
        Varible.nums -= 1

test = Varible()
test1 = Varible()
test2 = Varible()
Varible.nums

del test

This two

class Stack:
    def __init__(self, st = []):
        self.stack = []
        for i in st:
            self.push(i)

    def isEmpty(self):
        # if self.stack:
        #     return False
        # else:
        #     return True
        return not self.stack

    def push(self, obj):
        self.stack.append(obj)

    def pop(self):
        if self.stack:
            return self.stack.pop()
        else:
            print('warning, 栈为空!')

    def top(self):
        if self.stack:
            return self.stack[-1]
        else:
            print('warning, 栈为空!')

    def bottom(self):
        if self.stack:
            return self.stack[0]
        else:
            print('warning, 栈为空!')
阅读更多

没有更多推荐了,返回首页