首页 > 解决方案 > 对功能感到困惑

问题描述

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

def shortest_path(source, target):

    frontier_d = {}

    frontier_d[source]=1


    raise NotImplementedError

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

标签: pythonfunctionpycharm

解决方案


看看这个 ——什么时候使用“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}


推荐阅读