Raw Strings
00:04
In a raw string, escape sequence characters such as you saw in the last section are not interpreted. Now you’re going to see how to define a raw string and then how they are useful. Here, a new variable a
is defined with two pieces of text and a newline character in the middle.
00:29
You can see that when a
is printed out, it has that newline character obeyed when it’s printed. To create a raw string, the string is prefixed with an r
, as seen here. Otherwise, the content is exactly the same.
00:45
Printing this string out shows that the raw string means that the newline character is not interpreted by print()
and is left intact. This is useful in applications where the escape sequence characters are not to be interpreted normally, such as regular expressions, an area you may not be familiar with but one that’s extremely useful in text processing.
01:07 Regular expressions make use of the backslash character in a different way to normal text, and here raw strings come into their own by controlling the way that the string is interpreted. Regular expressions fall outside the scope of this course, but they’re well worth looking into if you ever need to process text.
sujan.dummy1 on Nov. 18, 2024
It would be good to also mention maximum and minimum integer and float values in their respective modules.
Become a Member to join the conversation.
UweSteiner on June 16, 2020
good overview - thanks