Page 88 - TP_V5.1_C8_fb
P. 88
Program 3: To display 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 STRINGS
Single-line strings 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 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.
For example,
address = '''
44A, Street No 1
Kailash Colony
New Delhi
'''
Program 5: To print multiline strings.
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.''')
86 Premium Edition-VIII

