There is also a way to print non-printable characters in the sense that they are executed as commands inside a line, even if they are not visible (transparent) in the line, and their presence can be observed by measuring the length of the line with len and also simply by placing the mouse cursor at the beginning of the line and by looking / counting how many times you need to press the arrow key to go from beginning to end, oddly enough, some individual characters can have a length of, for example, 3, which seems puzzling. (Not sure if this has already been demonstrated in previous answers)
In the screenshot below, I inserted a 135-bit string that has a specific structure and format (which I had to manually create for certain bit positions and its total length) so that it is interpreted by ascii by a specific program I 'and in the resulting printed line contains non-printable characters, such as a line break, which literally causes a line break (correction: form feed, a new page that I had in mind, not a line break), there is an additional print output the whole empty line between the printed result (see below):
An example of printing non-printable characters that appear on a printed line
Input a string:100100001010000000111000101000101000111011001110001000100001100010111010010101101011100001011000111011001000101001000010011101001000000 HPQGg]+\,vE!:@ >>> len('HPQGg]+\,vE!:@') 17 >>>
In the above code snippet, try copying and pasting the line HPQGg]+\,vE!:@ Directly from this site and see what happens when you paste it into Python IDLE.
Hint: You must click on the arrow / cursor three times to scroll through the two letters from P to Q , even if they appear next to each other, since there is actually a File Separator ascii command between them. them.
However, despite the fact that we get the same initial value when decoding it as a byte array into hexadecimal, if we convert this hexadecimal code back to bytes, they look different (maybe a lack of coding, I'm not sure), but In any case, the above program output prints non-printable characters (I accidentally stumbled upon this while trying to develop a compression method / experiment).
>>> bytes(b'HPQGg]+\,vE!:@').hex() '48501c514767110c5d2b5c2c7645213a40' >>> bytes.fromhex('48501c514767110c5d2b5c2c7645213a40') b'HP\x1cQGg\x11\x0c]+\\,vE!:@' >>> (0x48501c514767110c5d2b5c2c7645213a40 == 0b100100001010000000111000101000101000111011001110001000100001100010111010010101101011100001011000111011001000101001000010011101001000000) True >>>
In the 135-bit line above, the first 16 groups of 8 bits from the side with the direct byte order encode each character (including non-printable), while the last group of 7 bits leads to the @ character, as seen below:
Technical breakdown of the format of the above 135-bit string
And here is a breakdown of a 135-bit string as text:
10010000 = H (72) 10100000 = P (80) 00111000 = x1c (28 for File Separator) * 10100010 = Q (81) 10001110 = G(71) 11001110 = g (103) 00100010 = x11 (17 for Device Control 1) * 00011000 = x0c (12 for NP form feed, new page) * 10111010 = ] (93 for right bracket '] 01010110 = + (43 for + sign) 10111000 = \ (92 for backslash) 01011000 = , (44 for comma, ',) 11101100 = v (118) 10001010 = E (69) 01000010 = ! (33 for exclamation) 01110100 = : (58 for colon ':) 1000000 = @ (64 for '@ sign)
So, in conclusion, the answer to the sub-question about displaying non-printable in hexadecimal form in the byte array located above contains the letters x1c , which indicate the file separator command, which was also noted in the tooltip. An array of bytes can be considered a string, if you exclude the prefix b on the left side, and again this value is displayed in the print line, although it is invisible (although its presence can be observed, as shown above, with a hint and len command).