Discuss / Python / 测验

测验

Topic source

WALL_E91

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

def trim(s): l = len(s) if len(s) != 0: while s[0] == " ": s = s[1: l] l = len(s) if len(s) == 0: return s l = len(s) while s[l - 1] == " ": s = s[: l - 1] l = len(s) if len(s) == 0: return s return s

试了一下,好像没起作用,照原样打印出来了。。。我写的一段也是照原样打印出来了,所以我来借鉴一下,看问题出在哪儿

def trim(s): while s[0]=='': s.remove(s[0]) while s[-1]=='': s.remove(s[-1]) return s

trim(' hello ')


  • 1

Reply