繁体   English   中英

Python function 不返回 None 而不是元组列表

[英]Python function not returning None instead of list of tuples

我有一个 function 来返回一个元组列表。 我尝试在return语句之前的for循环中打印列表,它工作正常。 但是,当我调用 function 时,它返回None

def list_path(first, last):   
    path = []
    # ..... shortened code   
    while True:
        for x, y in neighbors(person.id):            
            # ... some more code                
            nextPair = (x, y)                                
            path.append(nextPair)                   
    return path  

这就是我如何调用 function path = list_path(source, target)

我有一个 if 语句,它在 function 调用之后使用 path 的值。 该值始终为None ,即使我对列表进行硬编码

好的,我发现了问题。 在我的代码中的某个时刻,我返回时没有任何价值。 此返回语句与位于 function 最后一行的语句不同。 感谢您的意见。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM