2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > python中newline什么意思 \newline转义序列在python中是什么意思?

python中newline什么意思 \newline转义序列在python中是什么意思?

时间:2023-12-11 03:32:19

相关推荐

python中newline什么意思 \newline转义序列在python中是什么意思?

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

解决方案

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

So, an example is like:

print("a\

b")

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

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 \, the source string contains the \x10 character and that is replaced by an empty string.

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。