Discuss / Python / 有个问题想要请教一下

有个问题想要请教一下

Topic source
def trim(s):
    while s[1] ==' ':
        s=s[1:]
    while s[-1]==' ':
        s=s[:-2]
    return s

请问这样为什么就会测试失败

雾是成风

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

因为列表下标是从0开始的啊,s[0]表示的是第一个元素,而s[1]指的是列表中的第二个元素


  • 1

Reply