Discuss / Python / exercise

exercise

Topic source

def trim(param): if not isinstance(param, str): raise TypeError:('Aha get a bad param') first, end = 0, -1 try: while param[first] is ' ': first += 1 while param[end] is ' ' end -= 1 return param[first:end] if end != -1 else param[first:] except IndexError: return ''


  • 1

Reply