Python 문자열 splitlines() 메서드
예시
문자열을 각 줄이 목록 항목인 목록으로 분할합니다.
txt = "Thank
you for the music\nWelcome to the jungle"
x = txt.splitlines()
print(x)
정의 및 사용
이 splitlines()
메서드는 문자열을 목록으로 분할합니다. 분할은 줄 바꿈에서 수행됩니다.
통사론
string.splitlines(keeplinebreaks)
매개변수 값
Parameter | Description |
---|---|
keeplinebreaks | Optional. Specifies if the line breaks should be included (True), or not
(False). Default value is False |
더 많은 예
예시
문자열을 분할하되 줄 바꿈을 유지합니다.
txt = "Thank
you for the music\nWelcome to the jungle"
x = txt.splitlines(True)
print(x)