Raw string on input? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

Raw string on input?

i want to receive an input from the user, and enforce the string received to be a raw string to escape special characters, for example if the user entered "i'm a string \n", i want the " \n" to be treated as a backslash and "n", and not as a new line. i hope someone understand me, thank you.

26th Nov 2019, 11:07 PM
Salih Benlalla
Salih Benlalla - avatar
2 ответов
+ 5
no need to do anything as far as i can see. I just done a simple input which had a \n and a \t and \\ and the output included everything I typed in.
26th Nov 2019, 11:31 PM
rodwynnejones
rodwynnejones - avatar
+ 5
Not sure if this meets your idea, but it works with regular input: res = input('test inp') # enter "i am a string\nhello" print(res) #output: "i am a string\nhello"
27th Nov 2019, 9:36 AM
Lothar
Lothar - avatar