擅长:python、mysql、java
<p>我将进一步阐述埃尔扎的正确回答和你的评论。在前面的回答中,可能会让您感到困惑和不安的是,在源代码中提供的Python字符串,以及Python控制台和ide向您显示的Python字符串,<em>开发人员</em>和字符串的打印方式(即向用户<em>显示)之间存在差异:</p>
<pre><code>>>> s = 'c:\\directory\\file.txt'
>>> s
'c:\\directory\\file.txt' <-- if you ask for the value, you will see double slashes
>>> print s
c:\directory\file.txt <-- if you print the string, the user will see single slashes
</code></pre>
<p>我认为您得到“系统找不到指定的路径”的原因是,您手动复制到剪贴板并从Python控制台/IDE粘贴一些内容(您的路径在您的问题中以引号显示也支持这一点)。</p>
<p>更让人困惑的是,你有时会使用单引号。只有一些斜线字符组合具有特殊含义(请参见<a href="https://docs.python.org/2/reference/lexical_analysis.html#string-literals" rel="nofollow">Python documentation</a>),例如<code>'\n'</code>表示新行,而其他的则没有,例如<code>'\s'</code>,它只打印为<code>\s</code>。</p>
<p>另外,转义</em>字符的原因是,对于Python/计算机来说,它们是向程序员传达文本中有哪些特殊字符的方便方式。例如,这样,在<code>'\t'</code>(制表符)和<code>' '</code>(一些空格)之间就没有歧义,实际上可以看到不可打印的/一些控制字符,等等</p>