0

I am a beginner and I want to make a simple program that would take an input and print it back in new line. This is how my code looks.

a=input("enter: ")
print(a)

output what i get:

enter: python\ncode
python\ncode

expected output:

enter: python\ncode
python
code
TechBee
  • 31
  • 5
  • Does this answer your question? [Replacing a text with \n in it, with a real \n output](https://stackoverflow.com/questions/42965689/replacing-a-text-with-n-in-it-with-a-real-n-output) – Green Cloak Guy Jul 25 '20 at 17:27
  • @GreenCloakGuy thankyou! it works. but i also want to know why does it not work if "\n" is given in input, like is it forbidden to be used in input. also hope you don't mind my english – TechBee Jul 25 '20 at 17:34

1 Answers1

0

Answer to this problem based on another Stack Overflow thread: Process escape sequences in a string in Python Decode the string before printing like this

    >>> a = input('Enter: ')
    Enter: python\ncode
    >>> a
    'python\\ncode'
    >>> print(a)
    python\ncode
    >>> print(bytes(a, "utf-8").decode("unicode_escape"))
    python
    code
    >>>