标签:oca 行存储 end int pre bin div 使用 col
1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 4 ‘‘‘ 5 本代码的目的是测试使用类对象来作为序列的成员进行存储 6 ‘‘‘ 7 class myClass(object): 8 def __init__(self, para1, para2, para3): 9 self._para1 = para1 10 self._para2 = para2 11 self._para3 = para3 12 13 def changePara(self, para1, para2, para3): 14 self._para1 = para1 15 self._para2 = para2 16 self._para3 = para3 17 18 def printPara(self): 19 print self._para1, self._para2, self._para3 20 21 if __name__ == ‘__main__‘: 22 mc = myClass(1, 2, 3) 23 mc.printPara() 24 mc.changePara(4, 5, 6) 25 mc.printPara() 26 ls = [] 27 mc1 = myClass(‘a‘, ‘b‘, ‘c‘) 28 mc2 = myClass(11, 22, 33) 29 ls.append(mc1) 30 ls.append(mc2) 31 print ls 32 for item in ls: 33 item.printPara()
执行结果:
1 [root@localhost tmp]# python classobj.py 2 1 2 3 3 4 5 6 4 [<__main__.myClass object at 0x7fa0f31f8a10>, <__main__.myClass object at 0x7fa0f31f8bd0>] 5 a b c 6 11 22 33
标签:oca 行存储 end int pre bin div 使用 col
原文地址:https://www.cnblogs.com/mrlayfolk/p/12103665.html