splitlines() function in python by R4R Team

- splitlines() is a python function which are used to split the string at the point of line break and store in form of list.

Syntax-

str.splitlines(number)

- here str is given string which we want to split.
- and if we add the number then it include the line break also.

Example

string is s="Thisnisnprogramming" where n shows the line break.
then s.splitlines() will give ["This","is","programming"]

and s.splitlines(10) will give ["Thisn","isn","programming"]


program-

s="thisnisnprogramming"
print("Original String isn",s)
print(s.splitlines())
print(s.splitlines(10))
print(s.splitlines(15))
print(s.splitlines(2))
print(s.splitlines(100))
print(type(s.splitlines()))


output-

Original String is
this
is
programming
['this', 'is', 'programming']
['thisn', 'isn', 'programming']
['thisn', 'isn', 'programming']
['thisn', 'isn', 'programming']
['thisn', 'isn', 'programming']
<'class 'list'>


-In this program, we have a string s="Thisnisnprogramming" where n shows the line break so splitlines() function split the string on the basis of n and store in list.
- all number as argument in splitlines() are work same. so we need not to worry about that.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!