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通常是相同的.