Discuss / Python / 一步切片

一步切片

Topic source

Exmlyshy

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

def trim(s): head=0 tail=len(s)-1 while 1: if s[head]==' ': head=head+1 if s[tail]==' ': tail=tail-1 if (s[head]!=' ')&&(s[tail]!=' '): break return s[head:tail+1]

空字符 tail会报错的吧。


  • 1

Reply