如何使用python将所有可打印ASCII字符的列表打印到控制台?[duplicate]

jv2fixgn  于 2023-01-27  发布在  Python
关注(0)|答案(1)|浏览(292)
    • 此问题在此处已有答案**:

Test if a python string is printable(10个答案)
4天前关闭。
某些ASCII字符是可打印的,而某些ASCII字符是不可打印的。
不可打印的ASCII字符如下所示:

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

问题是,如何使用python将可打印的ASCII字符打印到控制台?

5lhxktic

5lhxktic1#

下面的代码打印所有可打印字符:

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

for ch in characters:
    print(ch)

相关问题