Computer Science, asked by aneelkumarnand2346, 11 months ago

Write the output of the following python code #!/usr/bin/python
str = "Line1-a b c d e f\nLine2- a b
c\n\nLine4- a b c d"
print str.splitlines( )
print str.splitlines(O)
print str.splitlines(3)
print str.splitlines(4)
print str.splitlines(5)

Answers

Answered by shrutisingh089
0

#!/usr/bin/python

str = "Line1-a b c d e f\nLine2- a b

c\n\nLine4- a b c d"

print str.splitlines( )

print str.splitlines(O)

print str.splitlines(3)

print str.splitlines(4)

print str.splitlines(5)

Answered by Anonymous
1

The output of the code as per the question is given as follows:

str = " Line1-a b c d e f \n Line2-a b c \n \n Line 4- a b c d "

print (str . split lines())  // returns a list with splitted elements with no parameter

print (str . split lines(0)) // a parameter is passed

print (str . split lines(3)) // a parameter is passed

print (str . split lines(4)) // a parameter is passed

print (str . split lines(5)) // a parameter is passed

Output :

[ 'Line1-a b c d e f ', ' Line2-a b c', '', 'Line4- a b c d' ]

[ 'Line1-a b c d e f ', ' Line2-a b c', '', 'Line4- a b c d' ]  // same as above

[ 'Line1-a b c d e f \n ', ' Line2-a b c \n ', ' \n ', 'Line4- a b c d' ]

[ 'Line1-a b c d e f \n ', ' Line2-a b c \n ', ' \n ', 'Line4- a b c d' ]

  • The method split lines() is used to splits the string at line breaks and then returns a list of lines in the string.

Similar questions