What does preceding a string literal with “r” mean? [duplicate]
问题 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