简体   繁体   English

在Python 3中使用“”和转义序列?

[英]Using “”" and escape sequences in Python 3?

I am learning Python right now and wanted to try all the escape sequences but my code seems to have a bug. 我现在正在学习Python,想尝试所有的转义序列,但是我的代码似乎有一个错误。 Please help me find it? 请帮我找到它吗?

My Code: 我的代码:

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)

--> Error: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 137-146: unknown unicode character name ->错误:SyntaxError:(unicode错误)“ unicodeescape”编解码器无法解码位置137-146中的字节:未知的unicode字符名称

The culprits are \\N{prabhu} and \\U12345678 . 罪魁祸首是\\N{prabhu}\\U12345678

\\U12345678 is illegal because it is far behind the valid range limit ( 0010ffff ). \\U12345678是非法的,因为它远远超出了有效范围限制( 0010ffff )。 12345678 in hex is 305419896 where unicode ends at 1114111 ( 0010ffff ). 十六进制的12345678305419896 ,其中Unicode以11141110010ffff )结尾。

\\N{prabhu} is illegal because it is not a valid unicode char name. \\N{prabhu}是非法的,因为它不是有效的Unicode字符名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM