python 空行清除

python 有3种str 字符空行清除方法,分别为:
str.lstrip() # 清除左边第一个
str.rstrip() # 清除右边第一个
str.strip() # 清除两边

列:

s = "\nHello World\n "
print s.lstrip()
"Hello World\n"
print s.rstrip()
" \nHello World"
print s.strip()
"Hello World"

打开文件清除换行符
列:

hand = open('box.txt', 'r')
for line in hand:
    line = line.rstrip() # or strip
    print line
posted @ 2017-12-14 19:08  Mindfulness  阅读(10244)  评论(0编辑  收藏  举报