Reputation: 4330
I have written two recursive functions in python.
The first one takes parameters, modifies them, and returns a value.
def Similarity(string, sstring1, index):
if condition1:
return index
if condition2:
#do something
Similarity(string, string1, index)
The second one takes parameters and performs operations on a global variable.
def getData(i, value):
global dataList
if condition:
return list(suffixList)
#do something
getData(i, value)
These functions work perfectly and do the exact computations I need but always return a NoneType.
I haven't been able to figure out why.
Upvotes: 1
Views: 6723
Reputation: 1121834
You are not returning anything. Always use the return
statement to return a value from a function. Python does not use the last statement in a function as a return value.
def getData(i, value):
global dataList
if condition:
return list(suffixList)
#do something
return getData(i, value)
A function that exits without an explicit return
, returns None
instead.
Upvotes: 12