空白:含 \n
、\r
、空格、制表
lstrip
只从左开始向右扫描,遇到第一个非空白字符就立刻停;rstrip
只从右开始向左扫描,遇到第一个非空白字符就立刻停。
s = ' \t\nhello world\n\t '
# 左端:开头的空格、制表、换行
# 右端:结尾的换行、制表、空格
s.lstrip() # 'hello world\n\t '
s.rstrip() # ' \t\nhello world'
所以空行,没有非空白,即是左空白也是右空白
s = ' \t\n\r '
s.lstrip() # ''
s.rstrip() # ''
s.strip() # ''