Python 值在函数中正确打印,但返回时为None

Python 值在函数中正确打印,但返回时为None,python,list,function,recursion,return,Python,List,Function,Recursion,Return,我只是想温习一下我的python,所以我确信我在这里犯了一个基本的错误。我的代码只是一个玩具应用程序,可以在循环排序的数组中找到最大的项 这是我的密码: def listIsSorted(l): if l[0] < l[-1]: return 1 return 0 def findLargest(l): listLength = len(l) if(listLength == 1): return l[0] if(l

我只是想温习一下我的python,所以我确信我在这里犯了一个基本的错误。我的代码只是一个玩具应用程序,可以在循环排序的数组中找到最大的项

这是我的密码:

def listIsSorted(l):
    if l[0] < l[-1]:
        return 1
    return 0

def findLargest(l):
    listLength = len(l)
    if(listLength == 1):
        return l[0]
    if(listLength == 2):
        if(l[0] > l[1]):
            print("OMG I Found it: " + str(l[0]))
            return l[0]
        return l[1]

    halfway = int(listLength/2)
    firsthalf = l[:int(halfway)]
    secondhalf = l[int(halfway):]
    if(listIsSorted(firsthalf) and listIsSorted(secondhalf)):
        return max(l[halfway - 1], l[-1])
    elif (listIsSorted(firsthalf)):
        findLargest(secondhalf)
    else:
        findLargest(firsthalf)

l4 = [5,1,2,3]
print(findLargest(l4))

我的问题是:当它刚被打印为5时,为什么它被返回为type
None

def findLargest(l):
    listLength = len(l)
    if listLength == 1:
        return l[0]
    if listLength == 2:
        if l[0] > l[1]:
            print "OMG I Found it: {0}".format(l[0])
            return l[0]
        return l[1]

    halfway = int(listLength/2)
    firsthalf = l[:int(halfway)]
    secondhalf = l[int(halfway):]
    if listIsSorted(firsthalf) and listIsSorted(secondhalf):
        return max(l[halfway - 1], l[-1])
    elif listIsSorted(firsthalf):
        return findLargest(secondhalf)
    else:
        return findLargest(firsthalf)

苏..问题是什么?用明确的问题编辑。抢手货欣赏第二双眼睛。祝你过得愉快!
def findLargest(l):
    listLength = len(l)
    if listLength == 1:
        return l[0]
    if listLength == 2:
        if l[0] > l[1]:
            print "OMG I Found it: {0}".format(l[0])
            return l[0]
        return l[1]

    halfway = int(listLength/2)
    firsthalf = l[:int(halfway)]
    secondhalf = l[int(halfway):]
    if listIsSorted(firsthalf) and listIsSorted(secondhalf):
        return max(l[halfway - 1], l[-1])
    elif listIsSorted(firsthalf):
        return findLargest(secondhalf)
    else:
        return findLargest(firsthalf)