【发布时间】:2018-04-29 12:40:30
【问题描述】:
我现在正在学习 Python,想尝试所有转义序列,但我的代码似乎有错误。请帮我找到它?
我的代码:
string = """backslash - \\\nsingle quote - \'\ndouble quote - \"
ASCII bell - \a Lorem
ASCII backspace - \b Lorem
ACII formfeed - \f Lorem
Unicode - \N{prabhu} Ipsum
Carriage return - \r Ipsum
16 bit Hex value - \u1234
32 bit Hex value - \U12345678 ASCII Vertical tab - \v
Octal value character - \123
Hex value - \x12
"""
print(string)
--> 错误:SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 137-146: unknown unicode character name
【问题讨论】:
-
那个位置是否表示
\N{prabhu}的部分? -
肯定是
\N{prabhu}。这不是 unicode 字符名称。你想得到什么符号?如果你用一些有效的 unicode 字符名称替换它,它就可以完美地工作。
标签: python python-3.x