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)