Discuss / Python / 请教下为什么运行后“后面有空格会在前面呢”??

请教下为什么运行后“后面有空格会在前面呢”??

Topic source

定义函数

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


  • 1

Reply