class OldStyle:
def __init__(self,message):
print "这是",message
class NewStyle(object):
def __init__(self,message):
print "这是",message
if __name__ == '__main__':
old=OldStyle("老示类")
print old
print type(old)
print dir(old)
new=NewStyle("新式类")
print new
print type(new)
<__main__.OldStyle instance at 0x00000000022A7A08>
<type 'instance'>
['__doc__', '__init__', '__module__']
这是 新式类
<__main__.NewStyle object at 0x0000000001E899E8>
<class '__main__.NewStyle'>
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']
def __init__(self,message):
print "这是",message
class NewStyle(object):
def __init__(self,message):
print "这是",message
if __name__ == '__main__':
old=OldStyle("老示类")
print old
print type(old)
print dir(old)
new=NewStyle("新式类")
print new
print type(new)
print dir(new)
输出
这是 老示类<__main__.OldStyle instance at 0x00000000022A7A08>
<type 'instance'>
['__doc__', '__init__', '__module__']
这是 新式类
<__main__.NewStyle object at 0x0000000001E899E8>
<class '__main__.NewStyle'>
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']