Page 125 - Trackpad_V5_Book 8
P. 125
STRING
A sequence of characters which is enclosed or surrounded by single (‘ ’) or double (“ ”) quotes is
known as a string. The sequence may include a letter, number, special characters or a backslash.
Python treats single quotes as double quotes.
Example of a string:
CREATING STRINGS
Strings can be created by enclosing characters inside single or double quotes. It is like assigning
a value to a variable.
MULTILINE STRINGS
A multiline string in Python begins and ends with either three single quotes or three double quotes.
Any quotes, tabs, or newlines in between the “triple quotes” are considered part of the string.
Program 4: To create a string.
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 5: To print special symbols using escape sequences.
Functions, String and List in Python 123

