Page 77 - tp_Modula_v2.0
P. 77
Program 15: To perform various string operations.
Program15.py
File Edit Format Run Options Window Help
str = 'Orange Education'
print('str = ', str)
print('str[1] = ', str[1])
print('str[-1] = ', str[-1])
print('str[1:4] = ', str[1:4])
print('str[3:-1] = ', str[3:-1])
On running the above program, you will get the following output:
Output
str = Orange Education
str[1] = r
str[-1] = n
str[1:4] = ran
str[3:-1] = nge Educatio
Exercise
A. Tick ( ) the correct option.
1. Which of the following is used to insert special characters that are invalid in Python?
a. Escape sequence b. Indentation
c. Lists d. None of these
2. Which operator is used to repeat the string for a given number of times?
a. String concatenation operator b. String replication operator
c. len( ) d. None of these
3. Which of the following does string include?
a. Letter b. Number
c. Special characters d. All of these
4. Which of the following is correct about multiline string?
a. It begins and ends with either single quotes or single double quotes
b. It begins and ends with either double single quotes or double quotes
c. It begins and ends with either three triple quotes or three double quotes
d. It begins and ends with either three single quotes or three double quotes
String Handling in Python 75

