طريقة تقسيم خطوط Python String ()
مثال
قسّم سلسلة إلى قائمة يكون كل سطر فيها عنصر قائمة:
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)