今天在编写python面向对象概念的demo时,运行后发现报了一个错误:TypeError: object() takes no parameters
lass Person:
def __init__(self,uid,name):
self.uid = uid
self.name = name
def getUId(self):
return self.uid
def getName(self):
return self.name
person1 = Person(1,'person1')
person2 = Person(2,'person2')
print(person1.getUId())
print(person2.getName())
原来python的构造函数__init__(self,变量)是左右两边分别两个下划线