Page 158 - TP_Plus_v2.2_Class_8
P. 158
STRING
A sequence of characters which is enclosed or surrounded by single (' '), double (" "), or Triple
(''' ''') 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:
Program 3: To print a string
Program3.py
File Edit Format Run Options Window Help Output
str = "This is Shweta's pen." This is Shweta's pen.
print(str)
Creating a Single-line String
Single-line string can be created by enclosing characters inside single or double quotes. It is like
assigning a value to a variable.
Program 4: To create a single-line string
Program4.py
File Edit Format Run Options Window Help
first_name = 'Aadya'
print (first_name)
last_name = 'Kaushal' Output
print (last_name)
Aadya
str = ' '
print (str) Kaushal
Creating Multiline String
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 5: To create a string.
Program5.py
File Edit Format Run Options Window Help
print('''A sequence of
characters are called a string.
Strings are used by programming
languages to manipulate text such
as words and sentences.''')
156 Plus (Ver. 2.2)-VIII

