【python】python返回结果多了none(递归时)
把每个返回值的print使用return替代即可
例子:
def trim(s):
if s[:1]==" ":
s=s[1:]
retrim(s)
elif s[-1:]==" ":
s=s[:-1]
trim(s)
else:
print(s)
修改为:
def trim(s):
if s[:1]==" ":
s=s[1:]
return trim(s)
elif s[-1:]==" ":
s=s[:-1]
return trim(s)
else:
return s