Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (12.7k points)

Can anyone tell me what does preceding a sting literal with "r" means? I know that it's been used for building regular expressions across multiple lines as a method argument for re.compile(). So, what I thought was r maybe stands for RegExp

Example

regex = re.compile(

    r'^[A-Z]'

    r'[A-Z0-9-]'

    r'[A-Z]$', re.IGNORECASE

)

But What does r means in this case?

1 Answer

0 votes
by (26.4k points)

It means, the respective string is considered to be a raw string. 

So, All the escape codes will be ignored.

How '\n' will be treated as newline character, same like r'\n' will be considered as characters \ followed by n.

Click on this link for more details about Python string literals

Want to know more about Python? Come and join: python certification course

 

Related questions

0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...