Discuss / Python / 简单

简单

Topic source

    while len(s) and s[0]==' ':

        s=s[1:]

    while len(s) and s[-1]==' ':

        s=s[:-1]

    if len(s)==0:

        return ''

    else:

        return s

zhanglei74259

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

大佬 自学小白想问下 while len(s) and s[0]==' ':  这个len(s)在这里起什么作用啊

这一段

while len(s) and s[0] == ' ':

实际上是下面这一段的意思

while len(s) != 0 and s[0] == ' ':

zhanglei74259

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

真心感谢


  • 1

Reply