python中的__init__subclass
时间: 2023-10-21 22:04:05 浏览: 125
在Python中,__init_subclass__是一个特殊的魔法方法,当创建一个类时,它会自动执行父类的该魔法方法。该方法可以接收额外的参数,并对类进行一些初始化操作。在引用中的代码示例中,父类Parent的__init_subclass__方法被执行,并打印出相应的信息。子类Subclass继承了Parent类,并传递了name参数,通过__init_subclass__方法将该参数设置为类的属性。所以在打印Subclass.name时,输出的结果是'Python'。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [Python学习之路——类的魔法方法](https://blog.csdn.net/qq_43580193/article/details/103917043)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [python之wxPython应用实例](https://download.csdn.net/download/weixin_38630463/14865891)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文