Page 116 - Plus V4 with Adobe class 8
P. 116
Using Escape Sequences with Strings
Escape sequences or characters are used to insert special characters that are invalid in Python. Quotes are
special characters and to insert them in a string we must escape them with a \ character in front of them.
An escape sequence is a sequence of characters that does not represent itself when used inside a
character or string. It is typically used to specify actions such as carriage returns and tab movements.
The backslash (\) is a special character and is also known as the escape character in Python. It is used to
represent white space characters, for example, '\t' for tab, '\n' for new line, and '\r' is for carriage return.
Program 4: To print special symbols using escape sequences
You will get the following output:
Program 5: To print multi line strings
You will get the following output:
Traversing a String
Traversing means visiting each element and processing it as required by the program. We can access
the characters of a string one at a time using indexing.
114 Plus (Ver. 4.0)-VIII

