How To Split Multi-line String Into Multiple lines?

In this post, we will learn How To Split Multi-line String Into Multiple lines which we can perform using the built in function split().



As we know string can be two or more two characters and to compare and get any special character we can access each character. And to perform a split multi line string into multiple lines follow the line of code given below.

multiline_ string = "This is a\nmulti- line\ nstring."

# Split the multi- line string into multiple lines
lines = multiline_ string. split(" \n")

# Print each line on a separate line
for line in lines:
    print( line)

This is a

In the above code, the slipt() built in function can be used to split a given multi- line string “This is a\nmulti- line\ string.” into multiple lines as the first line will break after a and the second line will break after multi- line as there is /n which is used for breaking the line to next line.

The same phrase is also used in java and C++ to break the line to the next line and pass the control to the next line, Which is used for making the output presentable when everything is mixed up.


To learn more about How To Split Multi-line String Into Multiple lines at Splitting of a string as output into multiple lines ends. and which could also be used for breaking the line in any condition provided “/n” should be written in double quotes.

To learn more about python programming problems and tutorials related o different concepts and solutions to different problems that might be encountered. And to earn more about python visit: Multi-Dimensional List In Python.

To learn more about different programming languages like java, MongoDB, and python, problems related to them and important concepts to get a clear visit: beta python programming languages Solutions.

Leave a Comment

%d bloggers like this: