具有不同参数数量的多个构造函数
📁 python
是否可以在 Python 中的一个类中创建具有不同参数数量的多个构造函数?
class a : def __ init __ ( self, b ): pass def __ Init __ ( self ): pass pre> 在这种情况下,只能使用第二个构造函数创建类的实例,而记录 x = a (42) 将导致错误。
📁 python
是否可以在 Python 中的一个类中创建具有不同参数数量的多个构造函数?
class a : def __ init __ ( self, b ): pass def __ Init __ ( self ): pass pre> 在这种情况下,只能使用第二个构造函数创建类的实例,而记录 x = a (42) 将导致错误。