rawstring

What does preceding a string literal with “r” mean? [duplicate]

Deadly 提交于 2019-11-26 02:06:49
问题 This question already has an answer here: What exactly do “u” and “r” string flags do, and what are raw string literals? 7 answers I first saw it used in building regular expressions across multiple lines as a method argument to re.compile() , so I assumed that r stands for RegEx. For example: regex = re.compile( r\'^[A-Z]\' r\'[A-Z0-9-]\' r\'[A-Z]$\', re.IGNORECASE ) So what does r mean in this case? Why do we need it? 回答1: The r means that the string is to be treated as a raw string, which

What exactly do “u” and “r” string flags do, and what are raw string literals?

為{幸葍}努か 提交于 2019-11-25 21:37:43
问题 While asking this question, I realized I didn\'t know much about raw strings. For somebody claiming to be a Django trainer, this sucks. I know what an encoding is, and I know what u\'\' alone does since I get what is Unicode. But what does r\'\' do exactly? What kind of string does it result in? And above all, what the heck does ur\'\' do? Finally, is there any reliable way to go back from a Unicode string to a simple raw string? Ah, and by the way, if your system and your text editor charset