我有一个函数,可以查找图形中的所有路径。该函数返回所有路径的列表。以后如何在代码中使用此值?
def findpaths(attachednodes,startID,endID,path = []):
path = path + [startID]
if startID == endID:
return [path]
if startID not in attachednodes:
return []
paths = []
for n in attachednodes[startID]:
if n not in path:
newpath = findpaths(attachednodes,n,endID,path)
for new in newpath:
paths.append(new)
for i in range(len(paths)):
numflight = i
flight = paths[i]
flights.update({numflight: flight})
return paths
答案 0 :(得分:1)
您将函数调用放在变量赋值的右侧。该变量将具有返回值: 例如
def some_function():
return 10
x = some_function()
print(x) # will print 10