python tutorial 学习笔记(六)class
来源:互联网 发布:wc3html闯关软件答案 编辑:程序博客网 时间:2024/05/17 00:12
class ClassName( SuperClass ) :
A new name space is created, thus all assignments to local variables go into this new namespace.
When a class definitition ends, a class object is created.
attribute names: __doc__( the fist multil-line string ), __class__(class object), variable, function object
instantiation: __init__(self). How to create an instance: X = MyClass()
Instance Objects:
Attribute references: data attribute and method. MyClass.f is a function object, x.f is a method object.
Data attibutes override method attributes with the same name. Note that clients may add data attributes of their own to an instance object
Method Objects:
They are attribute of Instance Objects. the special thing about methods is that the object is passed as the first argument of the function
x.f() is equivalent to MyClass.f(x)
Inheritance:
Method reference are resolved as : the corresponding class attribute, descending down the chain of base classes.
All mehods in Python are virtual.
class BaseClass:
def toString(self):
return "in BaseClass"def f(self):
print self.toString()
class MyClass(BaseClass):
def toString(self):
return "in MyClass"def fb(self):
BaseClass.f(self)if __name__ == "__main__":
>>in MyClass
x = MyClass()
x.fb()
Two builtin functions: isinstance(obj,class), issubclass(class1,class2)
Multiple Inheritance:
class DerivedClassName(Base,Base2,Base3):
old-style classes’s method reference rule: depth-first, left-right
new-style class( any class which inherite from “object”):http://www.python.org/download/releases/2.3/mro/ .(too complicated for now, leave it for later)
Private Variables:
__spam is replaced with _classname__spam, but “__spam__” won’t.
- python tutorial 学习笔记(六)class
- Python tutorial笔记 class
- python tutorial 学习笔记(一)
- python tutorial 学习笔记(三)
- Python Tutorial(六):模块
- Python Tutorial(六):模块
- An ffmpeg and SDL Tutorial 学习笔记(六)
- python学习笔记(六)
- python 学习笔记(六)
- Python学习笔记(六)
- Python学习笔记(六)
- python学习笔记(六)
- Python学习笔记(六)
- Python学习笔记(六)
- Python Tutorial 学习笔记1
- Python Tutorial 学习笔记2
- ffmpeg的tutorial中文版学习笔记(六)
- Unity学习笔记六 - Survival Shooter Tutorial
- 网络中数据传输过程的解析
- GridView点击标题排序
- vc程序计时器(转)
- Ubuntu 10.10开启3D模式+设置桌面特效教程
- FIBS数列和
- python tutorial 学习笔记(六)class
- 专业为各种手机软件进行测试的公司
- 彻底解决SysFader:IEXPLORE.EXE应用程序错误
- VS2008无法启动asp.net提示“无法启动程序: http://localhost/.../test.asp...
- C# 操作Access的公共类
- g3电容屏失灵,电击疗法
- g3电容屏失灵,电击疗法
- 综合好几个人推荐C++教程
- subclipx v1.07 - 简单实用的轻量级多维剪贴板工具