-1

Some ASCII characters are printable and some ASCII characters are not printable.

The non-printable ASCII characters are shown below:

       0  NUL  (Ctrl-@)  NULL
       1  SOH  (Ctrl-A)  START OF HEADING
       2  STX  (Ctrl-B)  START OF TEXT
       3  ETX  (Ctrl-C)  END OF TEXT
       4  EOT  (Ctrl-D)  END OF TRANSMISSION
       5  ENQ  (Ctrl-E)  ENQUIRY
       6  ACK  (Ctrl-F)  ACKNOWLEDGE
       7  BEL  (Ctrl-G)  BELL (Beep)
       8  BS   (Ctrl-H)  BACKSPACE
       9  HT   (Ctrl-I)  HORIZONTAL TAB
      10  LF   (Ctrl-J)  LINE FEED
      11  VT   (Ctrl-K)  VERTICAL TAB
      12  FF   (Ctrl-L)  FORM FEED
      13  CR   (Ctrl-M)  CARRIAGE RETURN
      14  SO   (Ctrl-N)  SHIFT OUT
      15  SI   (Ctrl-O)  SHIFT IN
      16  DLE  (Ctrl-P)  DATA LINK ESCAPE
      17  DC1  (Ctrl-Q)  DEVICE CONTROL 1 (XON)
      18  DC2  (Ctrl-R)  DEVICE CONTROL 2
      19  DC3  (Ctrl-S)  DEVICE CONTROL 3 (XOFF)
      20  DC4  (Ctrl-T)  DEVICE CONTROL 4
      21  NAK  (Ctrl-U)  NEGATIVE ACKNOWLEDGE
      22  SYN  (Ctrl-V)  SYNCHRONOUS IDLE
      23  ETB  (Ctrl-W)  END OF TRANSMISSION BLOCK
      24  CAN  (Ctrl-X)  CANCEL
      25  EM   (Ctrl-Y)  END OF MEDIUM
      26  SUB  (Ctrl-Z)  SUBSTITUTE
      27  ESC  (Ctrl-[)  ESCAPE
      28  FS   (Ctrl-\)  FILE SEPARATOR
      29  GS   (Ctrl-])  GROUP SEPARATOR
      30  RS   (Ctrl-^)  RECORD SEPARATOR
      31  US   (Ctrl-_)  UNIT SEPARATOR

The question is, how to we print the printable ASCII characters to the console using python?

Toothpick Anemone
  • 4,290
  • 2
  • 20
  • 42
  • I don't see why a Q&A like this is useful. It's a straightforward matter of determining which characters are printable (which is a [research question](https://meta.stackoverflow.com/questions/261592), and there are any number of close-enough existing questions; I closed with one of them) and then iterating over them in a normal way. The problem statement also seems artificial, not practical - what *use is it* to print these values? – Karl Knechtel Jan 23 '23 at 03:03

1 Answers1

1

The following code prints all of the printable characters:

characters = [chr(num) for num in range(32, 127)]

for ch in characters:
    print(ch)
Toothpick Anemone
  • 4,290
  • 2
  • 20
  • 42