Die*_*Epp 27
你可以做一个.
ASCII = ''.join(chr(x) for x in range(128))
Run Code Online (Sandbox Code Playgroud)
如果您需要检查会员资格,还有其他方法可以做到:
if c in ASCII:
# c is an ASCII character
if c <= '\x7f':
# c is an ASCII character
Run Code Online (Sandbox Code Playgroud)
如果要检查整个字符串是否为ASCII:
def is_ascii(s):
"""Returns True if a string is ASCII, False otherwise."""
try:
s.encode('ASCII')
return True
except UnicodeEncodeError:
return False
Run Code Online (Sandbox Code Playgroud)
jh3*_*314 14
您可以使用该string模块:
import string
print string.printable
Run Code Online (Sandbox Code Playgroud)
这使:
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13104 次 |
| 最近记录: |