Python recursion returns None

前端 未结 2 1484
野的像风
野的像风 2021-01-29 07:38

This will be really funny... Given following python codes:

def getBinary(binaryInput, kSize, beginBit):
    if int(binaryInput[beginBit + kSize-1])=         


        
相关标签:
2条回答
  • 2021-01-29 07:55

    The code is missing in the else part:

    def getBinary(binaryInput, kSize, beginBit):
        if int(binaryInput[beginBit + kSize-1])==1:
            print 'entered!!!'
            shortE = binaryInput[beginBit:kSize+beginBit]
            print 'shortE is now: ', shortE
            print 'kSize is now: ', kSize
            return (shortE,kSize)
        else :
            print 'else entered...'
            kSize -=1
            return getBinary(binaryInput, kSize, beginBit)
            # ^^^^
    
    0 讨论(0)
  • 2021-01-29 07:56

    When a function ends without executing a return statement, it returns None. Instead of

    getBinary(binaryInput, kSize, beginBit)
    

    you mean

    return getBinary(binaryInput, kSize, beginBit)
    
    0 讨论(0)
提交回复
热议问题