我们下面的探讨基于Python3,我实际测试使用的是Python3.2,Python3与Python2在类函数的类型上做了改变 1,类定义语法 Python类定义以关键字class开头,一个类定义例子 class MyClass: """this is an example""" i = 123 def f(self): return "hello world" 当类定义一进入的时候,也就是class关键字一遇到的时候,就开
今天看了python部落翻译的一篇<一道python类的小题>文章,感觉挺有启发性,记录下来: print('A') class Person(object): print('B') def __int__(self,name): print('C') self.name = name print('D') print('E') p1= Person('name1') p2 = Person('name2') 输出结果: A B D E C C 这里首先需要理解是,一.python程序的运行规