Discuss / Python / Dict定义中,super()没带参数是什么意思?

Dict定义中,super()没带参数是什么意思?

Topic source

fhfuih

#1 Created at ... [Delete] [Delete and Lock User]
class Dict(dict):

    def __init__(self, **kw):
        super().__init__(**kw)

廖雪峰

#2 Created at ... [Delete] [Delete and Lock User]

固定用法,记住就行

Pre-Battier

#3 Created at ... [Delete] [Delete and Lock User]

python 2中在子类调用super一般这么用:

class Child_class(Parent_class):
    __init__(self):
        super(Child_class, self).__init__()    # 调用了Parent_class的__init__,创建了一个Parent_class对象

在python 3中把Child_classself两个参数作为super的默认参数传入了,就直接简写成

super().__init__()

当然,这里的Parent_class不一定是父类。这是另外的问题了。 个人拙见,望廖大指教。


  • 1

Reply