s = ' hello world \n'
s.strip()               # 'hello world'
s.lstrip()              # 'hello world \n'
s.rstrip()              # ' hello world'
t = '-----hello====='
t.lstrip('-')           # 'hello====='
t.strip('-=')           # 'hello'
从文件中读取多行数据,配合生成器表达式:
with open(filename) as f:
    lines = (line.strip() for line in f)
    for line in lines:
        print(line)
文档信息
- 本文作者:zhupite
- 本文链接:https://zhupite.com/python/python-strip.html
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)