In [4]: import re
In [5]: print(re.escape('\n'))
\
In [6]: print(re.escape(r'\n'))
\\n
In [7]: print(r'\n')
\n
In [8]: print('\n')
In [9]: print('\\n')
\n
The third example print(r'\n')
gives the output I want (also the last example).
BUT the string I want to print is a variable that was not defined as a raw string.
Needless to say I cannot manually add backslashes to the string.