在Python中,当我打印带有反斜杠的字符串时,它只打印一次反斜杠:
>>> print(r'C:\hi')
C:\hi
>>> print('C:\\hi')
C:\hi
Run Code Online (Sandbox Code Playgroud)
但我注意到,当您打印带有反斜杠的字符串元组时,它会打印双反斜杠:
>>> print((r'C:\hi', 'C:\\there'))
('C:\\hi', 'C:\\there')
Run Code Online (Sandbox Code Playgroud)
为什么打印元组时表现不同?
(请注意,这种情况在 Python 2 和 3 以及 Windows 和 Linux 中都会发生。)