定义函数
def trim(s): if s[0]== ' ': s=trim(s[1:]) print('前面有空格') if s[-1]== ' ': s=trim(s[:-1]) print('后面有空格') return s
实现 from absset import trim print(trim(' hello '))
结果 后面有空格 前面有空格 hello
Sign in to make a reply
别叫我志峰哥
定义函数
def trim(s): if s[0]== ' ': s=trim(s[1:]) print('前面有空格') if s[-1]== ' ': s=trim(s[:-1]) print('后面有空格') return s
实现 from absset import trim print(trim(' hello '))
结果 后面有空格 前面有空格 hello