9

I was learning about the format mini-language and I scrolled up to view some string things, and I wondered what Python considered printable, so I checked:

>>> string.printable
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'

Note at the end, along with other normal printable control-type characters like ^I, ^J, and ^M, there's also ^B and ^C.

What would be the use for these?

Georgy
  • 12,464
  • 7
  • 65
  • 73
Richard Haley
  • 247
  • 1
  • 2
  • 7

5 Answers5

7

\x0b is the U+000B, LINE TABULATION, and \x0c is U+000C, FORM FEED (FF).

Great. What does that mean, and why are they considered printable?

Back in the days of teletypes, ASCII provided these characters for advancing a sheet of paper through the printer. The line tabulation character was to a line feed like a horizontal tab was to a space. The printer could have a set of defined vertical tab stops, and a line tabulation character would be interpreted as a request to advance to the next one following the current line.

A form feed would advance to the top of the next page, however the device defined a page. (If it used a continuous paper feed, a "page" would be considered, say, 66 lines, and if you were currently on line 60, a form feed would simply advance 7 lines, to line 1 of the next page.)

On a modern terminal emulator, they tend not to have any particular meaning. Simple tests indicate that on an xterm, they both appear to be treated the same as a line feed followed by a space:

>>> print("x\x0cy")
x
 y
>>> print("x\x0by")
x
 y
>>>

Update: after seeing https://stackoverflow.com/a/58421132/1126841, it would appear isn't not just a space following the line feed, but rather a line feed not followed by a carriage return, i.e., the cursor advances one line without returning to the beginning of that line; compare with print("\n"), which advances to the beginning of the next line, regardless of where the cursor currently is. (That makes more sense, and I should have remembered that.)

chepner
  • 497,756
  • 71
  • 530
  • 681
4

These are types of whitespace characters:

>>> string.whitespace
' \t\n\r\x0b\x0c'

From the docs:

A string containing all ASCII characters that are considered whitespace. This includes the characters space, tab, linefeed, return, formfeed, and vertical tab.

We know this by following the docs for printable:

String of ASCII characters which are considered printable. This is a combination of digits, ascii_letters, punctuation, and whitespace.

And we know what these whitespace characters are by referencing unicode control characters:
\x0b is a vertical tab
\x0c is a form feed

MyNameIsCaleb
  • 4,409
  • 1
  • 13
  • 31
3

Those symbols are printable whitespaces (can also be obtained by string.whitespace). \x0b or \v is vertical tab and \x0c (\f) which is form feed (docs).

In various terminals the representation can be different, but usually \v looks like following:

>>> print("some\vtext\vhere")
some
    text
        here

\f forces the printer to eject the current page and to continue printing at the top of another. In terminal often displays as an empty line. Sometimes can be used to clear the screen.

That's why these symbols are considered as printable. However, representation and behavior may be quite different

Oleh Rybalchenko
  • 6,998
  • 3
  • 22
  • 36
0

From the docs for string.printable

String of characters which are considered printable. This is a combination of digits, letters, punctuation, and whitespace.

where whitespace is defined as

A string containing all characters that are considered whitespace. On most systems this includes the characters space, tab, linefeed, return, formfeed, and vertical tab.

These are whitespace characters.

Sayse
  • 42,633
  • 14
  • 77
  • 146
0

Those characters belong to the family of whitespace characters (you can check >>> string.whitespace and python documentation for it). Specifically, \x0b is Unicode U+B for "Line Tabulation" and the \x0c is Unicode U+C for "Form Feed".

Javier Silva Ortíz
  • 2,864
  • 1
  • 12
  • 21