Transforms special characters (like quotes) to escape sequences or to a raw string and builds literals. Also, the other way, unescaping is possible. 🛠
& build a string literal definition Escape setup Escape type: Classic (C style escape) Raw string Generated code (string literal) setup Max line length Escape Our other tools: More tools Punycode converter HTML cleanup tool HTML fixing tool ...
shortstringitem ::= shortstringchar | stringescapeseq longstringitem ::= longstringchar | stringescapeseq shortstringchar ::= <any source character except "\" or newline or the quote> longstringchar ::= <any source character except "\"> stringescapeseq ::= "\" <any source character> ...
Transforms special characters (like quotes) to escape sequences or to a raw string and builds literals. Also, the other way, unescaping is possible. 🛠
在python2中,可以直接用decode("string_escape")解决,但是python3中str类型无法decode,那么怎么办呢? 有两种方法,第一种来自stackoverflow https://stackoverflow.com/questions/26311277/evaluate-utf-8-literal-escape-sequences-in-a-string-in-python3
Escape sequences only recognized in string literals >>> '\u5120' '儠' #普通字符串会对\u转义,r不认 >>> r'\u5120' '\\u5120' 但即使在r-stirng里,引号也可以用反斜杠来转义,反斜杠仍然保留在结果中。 r"\"" is a valid string literal consisting of two characters: a backslash and a doub...
stringescapeseq ::= "\" <any source character> bytesliteral ::= bytesprefix(shortbytes | longbytes) bytesprefix ::= "b" | "B" | "br" | "Br" | "bR" | "BR" | "rb" | "rB" | "Rb" | "RB" shortbytes ::= "'" shortbytesitem* "'" | '"' shortbytesitem* '"' ...
SyntaxError: EOL while scanning string literal >>> '"My python\', lession' '"My python\', lession'>>>a ='"My python\', lession'>>>print(a)"My python', lession 备注:在交互式解释器,输出的字符串都是通过引号扩起来的,如果输出有单引号,那么最终用双引号扩起来,如果输出字符串有双引号,用单...
The escape sequence is a sequence of characters treated as special when the Python interpreter encounters it in the string literal. But how Python knows it is an escape sequence, so the escape sequence is represented using the backslash(‘\’)followed by the character. ...