有些人误以为官方列出的可打印字符是说英语的程序员使用的所有字符,但还有其他字符。
其他常用字符以反斜杠转义序列开头。
换句话说,如果忽略ASCII控制字符和英文写作中不常见的字符,那么程序员经常使用哪些字符?
他们在这里:
the_printables = """
!"#$%&'()*+,-./0123
456789:;<=>?@ABCDEFG
HIJKLMNOPQRSTUVWXYZ[
]^_`abcdefghijklmnop
qrstuvwxyz{|}~
"""
the_printables = "".join(the_printables.split())
the_oft_forgot = "\t\n\r\\"
the_useables = the_oft_forgot + the_printables
描述 | 转义序列 |
---|---|
标签 |
|
新线 |
|
回车 |
|
反斜杠 |
|
characters = [chr(num) for num in range(128)]
representations = [repr(ch)[1:-1] for ch in characters]
is_printable = lambda ch: ("\\" not in ch)
is_oft_forgot = lambda ch: ("\\" in ch) and ("\\x" not in ch)
printables = type(representations)(filter(is_printable, representations))
the_oft_forgot = type(representations)(filter(is_oft_forgot, representations))
print("\n".join(the_oft_forgot))
print("\n".join(printables))