python函数返回noneType

Anu*_*san 0 python recursion nonetype

我在python中编写了两个递归函数.

第一个接受参数,修改它们并返回一个值.

def Similarity(string, sstring1, index):
    if condition1:
        return index
    if condition2:
        #do something
    Similarity(string, string1, index)
Run Code Online (Sandbox Code Playgroud)

第二个接受参数并对全局变量执行操作.

def getData(i, value):
    global dataList
    if condition:
        return list(suffixList)
    #do something
    getData(i, value)
Run Code Online (Sandbox Code Playgroud)

这些函数完美地工作并执行我需要的精确计算但始终返回noneType.我还没弄清楚原因.

Mar*_*ers 9

你没有回来任何东西.始终使用该return语句从函数返回值.Python不不是一个函数作为返回值使用的最后一条语句.

def getData(i, value):
    global dataList
    if condition:
        return list(suffixList)
    #do something
    return getData(i, value)
Run Code Online (Sandbox Code Playgroud)

没有显式退出的函数会return返回None.