讲英语的人在字符串文字中使用最多的字符是什么字符,例如`“hello world”`?

问题描述 投票:0回答:1

有些人误以为官方列出的可打印字符是说英语的程序员使用的所有字符,但还有其他字符。

其他常用字符以反斜杠转义序列开头。

换句话说,如果忽略ASCII控制字符和英文写作中不常见的字符,那么程序员经常使用哪些字符?

string unicode escaping unicode-string unicode-escapes
1个回答
0
投票

他们在这里:

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
描述 转义序列
标签
\t
新线
\n
回车
\r
反斜杠
\\

如何获得可打印经常忘记字符

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))
© www.soinside.com 2019 - 2024. All rights reserved.