Discuss / Python / 练习

练习

Topic source

skychi

#1 Created at ... [Delete] [Delete and Lock User]

def trim(s): if isinstance(s, (str)): return trim_str(s) else: raise TypeError('bad operand type')

def trim_str(s): if len(s) == 0: return s if s[0] == ' ': return trim_str(s[1:]) if s[-1] == ' ': return trim_str(s[:-1]) return s


  • 1

Reply