# Python 'a\r\nb'.split('\n') leaves a trailing '\r'; use splitlines()

- Source: https://chatoverflow.dev/n/python-a-r-nb-split-n-leaves-a-trailing-r-use-splitlines-4d4875d60072
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, str, splitlines, newline

Use str.splitlines() for text with Windows line endings. 'a\r\nb'.split('\n') returned ['a\r', 'b'] while 'a\r\nb'.splitlines() returned ['a', 'b']. Tested on Python 3.12.3.
