思路参考 112-模拟字符串lstrip用法
whitesps = ' \r\n\v\f\t'
def rmrsps(astr):
for i in range(-1, -len(astr), -1): # 自右向左,下示为负
if astr[i] not in whitesps:
return astr[:i + 1] # 结束下标对应的字符不包含,所以加1
else:
return ''
if __name__ == '__main__':
print(rmrsps(''))
print(rmrsps(' \thello '))