对功能感到困惑

时间:2020-05-25 03:10:03

标签: python function pycharm

我正在开始制作函数,这是我现在的代码:

def shortest_path(source, target):

    frontier_d = {}

    frontier_d[source]=1


    raise NotImplementedError

基本上,我正在尝试制作字典并将源(函数的输入)作为与值1关联的键。但是,Pycharm告诉我源是未解决的引用。如果源是函数的输入,为什么会发生这种情况?

1 个答案:

答案 0 :(得分:0)

查看此- When to use 'raise NotImplementedError'?

source="abc"
target=156
def shortest_path(source, target):
    try:
        frontier_d = {}
        frontier_d[source]=target
        print(frontier_d)
    except:
        raise NotImplementedError
shortest_path(source, target)

输出:{'abc':156}