如何使用Python获取所有ASCII字符的列表? [英] How do I get a list of all the ASCII characters using Python?
本文介绍了如何使用Python获取所有ASCII字符的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找类似以下内容的东西:
I'm looking for something like the following:
import ascii
print(ascii.charlist())
将会返回类似 ["A","B","C","D"的内容....]
.
推荐答案
The constants in the string
module may be what you want.
所有ASCII大写字母:
All ASCII capital letters:
>>> import string
>>> string.ascii_uppercase
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
所有可打印 ASCII字符:
All printable ASCII characters:
>>> string.printable
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
对于 ASCII标准中定义的每个字符,请使用 chr
:
For every single character defined in the ASCII standard, use chr
:
>>> ''.join(chr(i) for i in range(128))
'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f'
这篇关于如何使用Python获取所有ASCII字符的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文