求问大神,为啥出现此类报错?
import networkx as nxG = nx.Graph()
G.add_edge(1, 2,{ 'weight': 20})
运行后为啥会报错?
Traceback (most recent call last):
File "C:/Users/Administrator/Desktop/python/35.py", line 3, in <module>
G.add_edge(1, 2,{ 'weight': 20})
TypeError: add_edge() takes 3 positional arguments but 4 were given
函数接受的参数个数,小于你传入的参数个数导致报错,应该因为你多传入一个参数了
把后面的字典去掉试试:
G.add_edge(1, 2)
TypeError: add_edge() takes 3 positional arguments but 4 were given
错误告诉你,add_edge只需要接收3个位置参数,但是你给了4个。 TypeError: add_edge() takes 3 positional arguments but 4 were given add_edge只需要接收3个参数你给了4个 G.add_edge函数你看上去只传了3个参数,实际上传了4个参数,类方法第一个参数一定是self
页:
[1]