\ newline转义序列在python中是什么意思? [英] What does the \newline escape sequence mean in python?

查看:661
本文介绍了\ newline转义序列在python中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在中找到了序列\newline python文档中的转义序列列表.我想知道它是如何使用的以及用于什么目的.至少在我的解释器中,这似乎只是被解释为'\n' + 'ewline':

I found the sequence \newline in a list of escape sequences in the python documentation. I wonder how it is used and for what. At least in my interpreter it seems this is just interpreted as '\n' + 'ewline':

>>> print('\newline')

ewline

推荐答案

它是指实际的换行符,即字符代码为"16"(0x10)的字符,而不是文本序列换行符".

It refers to the actual newline character - the one with character code "16" (0x10) - not the text sequence "newline".

因此,示例如下:

print("a\
b")

在这里,反斜杠由字符串内的换行符接续,并且打印的内容只是"ab"而没有任何区别.

Here, the backslash is succeeded by the newline, inside a string, and what is printed is just "ab" with nothing apart.

\n不同-在这里,反斜杠后面的字符是n(0x6e),并且在解析字符串时,此序列转换为\x10.在\<newline>上,源字符串包含\x10字符,并将其替换为空字符串.

it differs from \n - in here, the characer following the backslash is n (0x6e), and this sequence is translated to \x10 on parsing the string. On \<newline>, the source string contains the \x10 character and that is replaced by an empty string.

如果该页面上的文档显示的是\<newline>而不是\newline,则可能会更清晰.

Maybe the documentation on that page would be more clear if it would read \<newline> instead of just \newline.

这篇关于\ newline转义序列在python中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆