Python面向对象3

1、内部类python

内部类就是在类的内部定义的类,主要目的是为了更好的抽象现实世界。算法

2、魔术方法(构造函数和析构函数)函数

 1 #!usr/bin/python
 2 #coding:utf8
 3 
 4 class Milo():
 5     class Test():
 6         var1 = "neibulei"
 7     name = 'csvt'
 8 
 9     def __init__(self,n = 'baby'):
10         self.name = n
11         print "initializing......"
12 
13     def fun1(self):
14         print self.name
15         print 'public'
16         self.__fun2()
17     def __fun2(self):
18         print 'private'
19 
20     @classmethod
21     def classFun(self):
22         print 'class'
23 
24     @staticmethod
25     def staticFun(self):
26         print 'static'
27 
28     def __del__(self):
29         print 'releasing sources......'
30 
31 zou = Milo()

3、垃圾回收机制spa

Python采用垃圾回收机制清理再也不使用的对象;code

Python提供gc模块释放再也不使用的对象;对象

Python采用“引用计数”的算法方式来处理回收,即:当某个对象在其做用域内再也不被其余对象引用的时候,Python就自动清除对象;blog

Python的函数collect()能够一次性收集全部待处理的对象(gc.collect())。作用域

相关文章
相关标签/搜索