What can be more effective to use? (python) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What can be more effective to use? (python)

I have written all the description about the question in the code!! https://code.sololearn.com/c1N1vvj6qLW7/?ref=app

14th Feb 2021, 5:33 PM
∆BH∆Y
∆BH∆Y - avatar
3 Answers
+ 2
∆BH∆Y It is used often when creatinf regex patterns. Because regular expressions mostly consist of escape charactees. Some Examples: \w ---> word/char \d ---> digit \s ---> space More here: https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/python_regex.asp We need to use r-prefix to escape and preserve backslash that is needed for processing regex in the background program. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Another use of r-prefix or ignoring escape sequence is for opening files. Sometimes, backslash is used to separate each location/directory. file = open("...\user\folder\text.txt") However, this will escape the \t in \text.txt. Therefore we should avoid escaping sequence by using r-prefix or escaping the backslash themselves. file = open("...\\user\\folder\\text.txt") OR file = open(r"...\user\folder\text.txt")
18th Feb 2021, 5:11 AM
noteve
noteve - avatar
0
r-strings are actually normal strings where every '\' is automatically substituted with '\\' So there is no difference
14th Feb 2021, 6:02 PM
Angelo
Angelo - avatar
0
R-strings is very helpful for regex. https://docs.python.org/3/howto/regex.html#the-backslash-plague
14th Feb 2021, 6:51 PM
portpass