How to print escape sequence when list type conversion str type

55 views Asked by At

For example, I have a list

l = ['\n']

conversion to str

s = str(l)

it's output

['\n']

I want to print a linefeed. What should I do. I try to remove '[' and "'"

print(s.replace('[','').replace(']','').replace("'",""))

It's have no effect.

1

There are 1 answers

2
yellow up On

Solve. when list to str,It's Why print \n.instead of linefeed. beacause it not conversion a linefeed,but a \\n character.so,just use \n replace \\n.

s.replace("\\n","\n")