Python String splitlines () Metode
Contoh
Pisahkan string menjadi daftar di mana setiap baris adalah item daftar:
txt = "Thank
you for the music\nWelcome to the jungle"
x = txt.splitlines()
print(x)
Definisi dan Penggunaan
Metode splitlines()
ini membagi string menjadi daftar. Pemisahan dilakukan pada jeda baris.
Sintaksis
string.splitlines(keeplinebreaks)
Nilai Parameter
Parameter | Description |
---|---|
keeplinebreaks | Optional. Specifies if the line breaks should be included (True), or not
(False). Default value is False |
Lebih Banyak Contoh
Contoh
Pisahkan string, tetapi pertahankan jeda baris:
txt = "Thank
you for the music\nWelcome to the jungle"
x = txt.splitlines(True)
print(x)