0
点赞
收藏
分享

微信扫一扫

python2 的新式类和老式类

小桥流水2016 2022-08-02 阅读 61
编程语言

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)
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__']

举报

相关推荐

0 条评论