Why do backslashes appear twice while printing in Python?

PythonServer Side ProgrammingProgramming

Backslash is an escape character. It is used to escape characters like quotes, double quotes, new line, etc. When we print a string containing a backslash, we see it twice because a backslash is also needed to escape itself. It means that we are telling the interpreter that this backslash is to be used as a backslash only and not as an escape character. For example,

print 'hello \\ John\'s friends'


"hello \ John's friends"
Published on 13-Dec-2017 15:14:22