python:TypeError: this constructor takes no arguments解决方法

来源:互联网 发布:数学分析书籍知乎推荐 编辑:程序博客网 时间:2024/06/06 07:42

学习self用法,

class Person:     def _init_(self,name):              self.name=name     def sayhello(self):              print 'My name is:',self.namep=Person('Bill')print p
出错:TypeError: this constructor takes no arguments

原因是初始化函数应为两个下划线__init__(self,name)


0 0
原创粉丝点击