Discuss / Python / 第一次发作业不知道对不对

第一次发作业不知道对不对

Topic source

def trim(s): if s[0] == 0: return(s[1:]) elif s[-1] == 0: return(s[:-2]) elif s[0] == 0 and s[-1] == 0 : return(s[1:-2]) else : return s

xiao正宇

#2 Created at ... [Delete] [Delete and Lock User]
if len(s) == 0:
        return s
while s[0] ==' ':
    s = s[1:]
    if len(s) == 0:
        return s
while s[-1] ==' ':
    s = s[:-1]
return s

  • 1

Reply