def string_reverse(): s = "abcdrfg" for i in range(len(s) - 1, -1, -1): print(s[i], end="")
gfrdcba
def string_reverse(): s = "abcdrfg" print(s[::-1])
gfrdcba
def string_reverse(): s = "abcdrfg" for char in reversed(s): print(char, end="")
gfrdcba
def string_reverse(): s = "abcdrfg" print("".join(reversed(s)))
gfrdcba
def string_reverse(): s = "abcdrfg" i = len(s) while i > 0: i -= 1 print(s[i], end="")
gfrdcba
def traverse_string_backwards(s): print("s:", s) if len(s) == 0: return traverse_string_backwards(s[1:]) print("s:", s, "s[0]:", s[0])
''' s: abcdrfg s: bcdrfg s: cdrfg s: drfg s: rfg s: fg s: g s: s: g s[0]: g s: fg s[0]: f s: rfg s[0]: r s: drfg s[0]: d s: cdrfg s[0]: c s: bcdrfg s[0]: b s: abcdrfg s[0]: a '''
标签:string,gfrdcba,print,abcdrfg,def,reverse From: https://www.cnblogs.com/huafan/p/17255952.html