0

How would I use \n in Python as a string?

Use Examples:

If you are making a string calculator, and using \n to separate the numbers/text from each other and put them individually into a list, which the conclusion for example:

24\n10\nhi
This should get a list like this:

[ '24', '10', 'hi']

What is the solution?

We can simply use one of the following solutions:

r"\n"

OR

"\\n"

Code example:

Comments
  • 0
    I mean, true. Who would ever write entire multi-line string literal for a mere line break?

    lines = text.split("""

    """)

    (P. S.: devRant, why do you keep inserting empty line???)
Add Comment