Why does the string concatenation operation 'A'+'''+'B'+'\'+'C' produce the string 'A'B\C' instead of a single backslash. How to fix this?
There's nothing to fix.
And I don't want to make use of the print function to generate this pattern. I want this to be printed in the >>> prompt.
That's nonsensical and not possible.
The python console shows the representation (repr
) of the object. The repr
of a string always escapes backslashes (and includes delimiter quotes) such that it can be pasted as-is as a string literal.
That is also why it changes the delimiter quotes depending on what quote style is embedded in the string (if any):
>>> '"'
'"'
>>> '\''
"'"