Python 打印两个反斜杠而不是一个 [英] Python prints two backslash instead of one
问题描述
我的目标是在 Python3 中打印一个反斜杠.我的输入是
links22 = ['1',"n","nkf"]treee = ['<img src={} \>'.format(i) for i in links22]打印(树)
我得到的输出是:
['<img src=1 \\>', '<img src=n \\>', '<img src=nkf \\>']
当我尝试时:
print("\\")
输出为:
<预><代码>\我想弄清楚为什么第一个输出是 \ 而第二个是 .
您可以在这里找到答案:https://docs.python.org/3/library/re.html?highlight=comment%20strings
<预><代码>\转义特殊字符(允许您匹配诸如*"、?"等字符),或表示特殊序列;下面讨论特殊序列.
Python 字符串文字支持的大多数标准转义符也被正则表达式解析器接受:
\a \b \f \n\N \r \t \u\U \v \x \\
My goal is to print a backslash in Python3. My input is
links22 = ['1',"n","nkf"]
treee = ['<img src={} \>'.format(i) for i in links22]
print(treee)
The output that I get is:
['<img src=1 \\>', '<img src=n \\>', '<img src=nkf \\>']
And when I try:
print("\\")
The output is:
\
I want to figure out why the first output is \ and in the second is .
The answer you can find here: https://docs.python.org/3/library/re.html?highlight=comment%20strings
\
Either escapes special characters (permitting you to match characters like '*', '?', and so forth), or signals a special sequence; special sequences are discussed below.
Most of the standard escapes supported by Python string literals are also accepted by the regular expression parser:
\a \b \f \n
\N \r \t \u
\U \v \x \\
这篇关于Python 打印两个反斜杠而不是一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!