Escape Sequences and Raw Strings

Escape Sequences

The table of Escape Sequnces can be found on the Strings tab. Back slashes are used to allow special byte codes: Escape Sequences.The backslash "\" and the following character(s) are replaced by a single character which has a binary value specified by the character(s).


This string gives this result because of the escape sequences in it. The 2 is on a newline because of \n, the 3 is tabbed because of the \t, and the backslash also on a newline and is shown because we escaped the backslash itself with \\. The built-in function len() returns the length of the string which is showing 7 and not 11 because escape sequences are one character and thus is showing 7 bytes.



Raw Strings

An r preceding the string will make it a raw string. This will ignore the escape sequences inside the string. Otherwise the code below would have a \n and a \t in it.