LLa*_*LaP 27 python string whitespace escaping
键入string.whitespace
为您提供一个字符串,其中包含Python string
模块定义的所有空白字符:
'\t\n\x0b\x0c\r '
Run Code Online (Sandbox Code Playgroud)
双方\x0b
并\x0c
似乎给了一个垂直的标签.
>>> print 'first\x0bsecond'
first
second
Run Code Online (Sandbox Code Playgroud)
\v
给出了同样的效果.这三种有什么不同?为什么string
模块使用\x0b
或\x0c
更简单\v
?
Mar*_*ers 43
\v
是 \x0b
:
>>> '\v'
'\x0b'
Run Code Online (Sandbox Code Playgroud)
但Python中的字符串文字表示使用的是\x0b
符号.
Python字符串文字表示仅使用\n
,\r
而且\t
,其他所有不是可打印ASCII字符的字符都使用\xhh
符号表示.
\x0c
是一种形式的饲料 ; 它迫使打印机移动到下一张纸.您也可以\f
在Python中表达它:
>>> '\f'
'\x0c'
Run Code Online (Sandbox Code Playgroud)
在终端中,效果\v
和\f
通常是相同的.