Python String 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)