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())。作用域

相關文章
相關標籤/搜索