【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


posted @ 2019-02-14 16:53  启*敬  阅读(1032)  评论(0编辑  收藏  举报