【问题标题】:Can somebody please justify this output?有人可以证明这个输出吗?
【发布时间】:2019-06-01 10:47:31
【问题描述】:

我只想正确解释为什么使用对象打印 __init__method 会给出“无”输出。

class cars:
    wheels = 4

    def __init__(self):
        self.mil = 10
        self.company = "BMW"

c1 = cars()
print(c1.__init__())

【问题讨论】:

  • __init__ 不返回任何内容 - 这在 python 中意味着它返回 None

标签: python python-3.x oop


【解决方案1】:

__init__ 不会显式返回任何内容,因此它会隐式返回 None,这就是您所看到的结果。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多