def trim(s):
start = 0
end = len(s)
while start < end and s[start] == " ":
start = start + 1
while end > start and s[end-1] == " ":
end = end - 1
return s[start:end]
s = input("请输入任意文本:")
print(trim(s))
Sign in to make a reply
Ashen One
def trim(s):
start = 0
end = len(s)
while start < end and s[start] == " ":
start = start + 1
while end > start and s[end-1] == " ":
end = end - 1
return s[start:end]
s = input("请输入任意文本:")
print(trim(s))