python即是脚本语言,又是OO语言。
但python的class和静态语言的又不同。
特点:
1. 使用一个名为 __init__ 的方法来完成初始化。
2. 使用一个名为 __del__ 的方法来完成类似析构操作。
3. 所有的实例方法都拥有一个 self 参数来传递当前实例,类似于 this。
4. 可以使用 __class__ 来访问类型成员。
注意:
在py文件中,class的定义在代码的最前面,否则无法引用class。
#!/usr/bin/python # class should be front of code class test: def __init__(self): print "init" def Foo(self): print id(self) def hello(): print "call hello func" if __name__=="__main__": print "hello world" hello() a=test() a.Foo()