首页 > 编程语言 > 详细

Python面向对象3

时间:2014-03-11 23:17:04      阅读:482      评论:0      收藏:0      [点我收藏+]

一、内部类

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

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

bubuko.com,布布扣
 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()
bubuko.com,布布扣

三、垃圾回收机制

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

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

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

Python的函数collect()可以一次性收集所有待处理的对象(gc.collect())。

Python面向对象3,布布扣,bubuko.com

Python面向对象3

原文:http://www.cnblogs.com/whp2011/p/3595197.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!