# 使用递归以相反的顺序打印字符串
def reverse_print(s):
if len(s) == 0:
return ''
else:
return s[-1] + reverse_print(s[:-1])
def test_reverse_print():
s = 'abcdefg'
assert reverse_print(s) =='gfedcba'
# 使用递归以相反的顺序打印字符串
def reverse_print(s):
if len(s) == 0:
return ''
else:
return s[-1] + reverse_print(s[:-1])
def test_reverse_print():
s = 'abcdefg'
assert reverse_print(s) =='gfedcba'
本文标题:Day22:使用递归以相反的顺序打印字符串
本文链接:https://www.haomeiwen.com/subject/bzmwxktx.html
网友评论