>>> print r'\u'
>>> print ur'\u'
File "<stdin>", line 1
SyntaxError: (unicode error) 'rawunicodeescape' codec can't decode bytes in position 0-1: truncated \uXXXX
我初學 python 時記得書上說前面有 r 的字符串 \ 沒有特殊含義，但后來發現我錯了，實際上字符串里的最后一個 \ 還是被莫名其妙轉義了（r'\' 和 ur'\' 都會出錯，只要引號里最后一個字符是反斜杠）……好吧，這也就算了。但是上面那個例子，unicode 和 str 的行為居然不一樣，請問這是 BUG 還是什麼……哪位高手能詳細說一下 r'' 和 ur'' 到底是干嘛的？是不是還有其他的反斜杠后的字符會被偷偷地轉義？我真的越來越搞不懂了……謝謝~
2.4.1. String literals
When an 'r' or 'R' prefix is present, a character following a backslash is included in the string without change, and all backslashes are left in the string. For example, the string literal r"\n" consists of two characters: a backslash and a lowercase 'n'. String quotes can be escaped with a backslash, but the backslash remains in the string; for example, r"\"" is a valid string literal consisting of two characters: a backslash and a double quote; r"\" is not a valid string literal (even a raw string cannot end in an odd number of backslashes). Specifically, a raw string cannot end in a single backslash (since the backslash would escape the following quote character). Note also that a single backslash followed by a newline is interpreted as those two characters as part of the string, not as a line continuation.
When an 'r' or 'R' prefix is used in conjunction with a 'u' or 'U' prefix, then the \uXXXX and \UXXXXXXXX escape sequences are processed while all other backslashes are left in the string. For example, the string literal ur"\u0062\n" consists of three Unicode characters: ‘LATIN SMALL LETTER B’, ‘REVERSE SOLIDUS’, and ‘LATIN SMALL LETTER N’. Backslashes can be escaped with a preceding backslash; however, both remain in the string. As a result, \uXXXX escape sequences are only recognized when there are an odd number of backslashes.