【问题标题】:Why isn't this simple code running? (copied from JournalDev) [duplicate]为什么这个简单的代码没有运行? (从 JournalDev 复制)[重复]
【发布时间】:2020-12-24 16:23:28
【问题描述】:

Here is its image这是代码

class Person:
    def _init_(self,n):
        self.name=n
    def get_person_name(self):
        return self.name
p1=Person("David")
p2=Person("Lisa")
print("Name",p1.get_person_name())
print("Name",p2.get_person_name())

【问题讨论】:

标签: python python-3.x


【解决方案1】:

您的 _init_ 方法应为 __init__ - 前后加双下划线

【讨论】:

    猜你喜欢
    • 2018-12-18
    • 2015-09-30
    • 1970-01-01
    • 2011-08-30
    • 1970-01-01
    • 2013-07-05
    • 2017-02-07
    • 2019-04-21
    • 2021-07-20
    相关资源
    最近更新 更多