- 用法:- str.splitlines(keepends=False)
- 返回字符串中的行列表,在行边界处中断。换行符不包含在结果列表中,除非给出 - keepends并且为真。- 此方法在以下行边界上拆分。特别是,边界是通用换行符的超集。 - 表示 - 说明 - \n- 换行 - \r- 回车 - \r\n- 回车 + 换行 - \v或- \x0b- 行制表 - \f或- \x0c- 换页 - \x1c- 文件分隔符 - \x1d- 组分隔符 - \x1e- 记录分隔符 - \x85- 下一行(C1 控制代码) - \u2028- 行分隔符 - \u2029- 段落分隔符 - 在 3.2 版中更改: - \v和- \f添加到行边界列表中。- 例如: - >>> 'ab c\n\nde fg\rkl\r\n'.splitlines() ['ab c', '', 'de fg', 'kl'] >>> 'ab c\n\nde fg\rkl\r\n'.splitlines(keepends=True) ['ab c\n', '\n', 'de fg\r', 'kl\r\n']- 与给定分隔符字符串 - sep时的- split()不同,此方法为空字符串返回一个空列表,并且终端换行符不会导致额外的行:- >>> "".splitlines() [] >>> "One line\n".splitlines() ['One line']- 为了比较, - split('\n')给出:- >>> ''.split('\n') [''] >>> 'Two lines\n'.split('\n') ['Two lines', '']
相关用法
- Python str.split用法及代码示例
- Python str.strip用法及代码示例
- Python str.isidentifier用法及代码示例
- Python str.expandtabs用法及代码示例
- Python str.isupper用法及代码示例
- Python str.title用法及代码示例
- Python str.rstrip用法及代码示例
- Python str.lstrip用法及代码示例
- Python str.removeprefix用法及代码示例
- Python str.zfill用法及代码示例
- Python str.format_map用法及代码示例
- Python str.removesuffix用法及代码示例
- Python str() vs repr()用法及代码示例
- Python string转integer用法及代码示例
- Python string strip()用法及代码示例
- Python string.octdigits用法及代码示例
- Python string.whitespace用法及代码示例
- Python strip()用法及代码示例
- Python str()用法及代码示例
- Python string capitalize()用法及代码示例
注:本文由纯净天空筛选整理自python.org大神的英文原创作品 str.splitlines。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
