Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Use \n in Python as a normal string

I am making a string calculator using numbers. For example:
154 + 246 = 154246

So the user will enter an input of a group of numbers, to separate the numbers using \n. As you know, \n is used to make a new line, but I need to use at as any normal string. I need to separate the numbers using \n into a list.

Code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

num_list = []
# this function will add a number to the list
def ask_num():
    # ask for a number (we will make it a string so we can add comma and /n)
    num = input("Enter numbers: ")

    
# run the function for asking numbers
ask_num()

>Solution :

You can use

r"\n"

or

"\\n"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading