一个有趣python self的题目

来源:互联网 发布:剑指offer python 编辑:程序博客网 时间:2024/06/08 05:40

#-*- encoding:utf-8 -*-
 
class Box:
    count=0
    def __init__(self,length,width,height):
        self.length = length
        self.width = width
        self.height = height
        Box.count = Box.count + 1
         
 
    def output(self):
        self.__v = self.length*self.width*self.height
        print "length:" + str(self.length)
        print "width:" + str(self.width)
        print "height:" + str(self.height)
        print "V:" + str(self.__v)
        print "run times:" + str(Box.count)
 
b1 = Box(1,2,3)
b1.output()
b2 = Box(2,3,4)
b2.output()
b3 = Box(3,4,5)
b3.output()
b4 = Box(4,5,6)
b4.output()
b5 = Box(6,7,8)
b5.output()

原创粉丝点击