Discuss / Python / 作业

作业

Topic source
def trim(l):    while(l[:1])==' ':        l=l[1:]    while(l[-1:])==' ':        l=l[:-1]    return l# 测试:if trim('hello  ') != 'hello':    print('1测试失败!')elif trim('  hello') != 'hello':    print('2测试失败!')elif trim('  hello  ') != 'hello':    print('3测试失败!')elif trim('  hello  world  ') != 'hello  world':    print('4测试失败!')elif trim('') != '':    print('5测试失败!')elif trim('    ') != '':    print('6测试失败!')else:    print('测试成功!')

  • 1

Reply