pikaqiu96 2015-03-15 12:31 采纳率: 0%
浏览 2352
已结题

pathon问题,在线求解

#!/usr/bin/python

class Vector:
def init(self,a,b):
self.a = a
self.b = b
def init(self):
return 'Vector (%d,%d)' % (self.a,self.b)

def add(self,other):
return Vector(self.a + other.a, self.b+other.b)

v1 = Vector(1,2)
v2 = Vector(3,4)
print(v1+v2)


运行结果:
root@kali:~/Desktop# python t2.py
Traceback (most recent call last):
File "t2.py", line 13, in
v1 = Vector(1,2)
TypeError: init() takes 1 positional argument but 3 were given
大家帮看看问题在哪儿

  • 写回答

5条回答 默认 最新

  • oyljerry 2015-03-15 13:58
    关注

    init是成员函数,不是构造函数,你需要定义实现__init__函数。

    评论

报告相同问题?