Par*_*jan 1 python oop python-2.7
我是否知道为什么myClass1以及myClass2在覆盖__new__()方法方面表现不同?建议哪种方式写一个类,为什么?我想myClass1():甚至不打电话__new__(cls),我是对的吗?
$ python
Python 2.7.5+ (default, Sep 19 2013, 13:49:51)
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class myClass1():
... def __new__(cls):
... print cls.__name__
...
>>> class myClass2(object):
... def __new__(cls):
... print cls.__name__
...
>>> o1 = myClass1()
>>> o2 = myClass2()
myClass2
>>>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
53 次 |
| 最近记录: |