Pyhton 去除字符串首尾的空格:
def trim(s):
while s[:1]==' ':
s = s[1:]
while s[-1:]==' ':
s = s[:-1]
return s
str =' Runoob '
print(trim(str))
Pyhton 去除字符串首尾的空格:
def trim(s):
while s[:1]==' ':
s = s[1:]
while s[-1:]==' ':
s = s[:-1]
return s
str =' Runoob '
print(trim(str))