June 2017
Beginner
352 pages
8h 39m
English
Sometimes, particularly when dealing with strings such as Windows filesystem paths or regular expression patterns which use backslashes extensively, the requirement to double-up on backslashes can be ugly and error prone. Python comes to the rescue with its raw strings. Raw strings don't support any escape sequences and are very much what-you-see-is-what-you-get. To create a raw string, precede the opening quote with a lower-case r:
>>> path = r'C:\Users\Merlin\Documents\Spells'>>>>>> path'C:\\Users\\Merlin\\Documents\\Spells'>>> print(path)C:\Users\Merlin\Documents\Spells
Read now
Unlock full access