important-question-answers-string-manipulation-in-python-class-11
important-question-answers-string-manipulation-in-python-class-11
(d)
i
e et
Pr
by
Chapter – 5: STRING MANIPULATION
Very Short answer Type Questions
Q.1
m
which of the following is not a Python legal string operation?
co
(a)‟abc‟+‟abc‟ (b) „abc‟*3 (c)‟abc‟ + 3 (d)‟abc‟.lower()
u.
Ans: /, // and %
R
Q.3 From the string S = “CARPE DIEM”. Which ranges return “DIE” and “CAR”?
on
i
(c) -1 (d) 6
et
(e) -1 (f) False
e
(g) False (h) False
Pr
(i) False
Short Answer Type Questions
by
Q.1 What is a string slice? How is it useful?
m
Ans: String Slice is a part of a string containing some contiguous characters from the string. It is
accessed from the string by providing a range in ―[ ]‖ brackets i.e. S [n:m]. Python returns all
co
the characters at indices n, n+1, n+2 . . . m-1 e.g.
u.
Q.2 Write a python script that traverses through an input string and prints its characters
ib
Q.3 Which functions would you chose to use to remove leading and trailing white spaces
pl
Ans: Python String strip() function will remove leading and trailing whitespaces. If you want to
remove only leading or trailing spaces, use lstrip() or rstrip() function instead.
Q.4 Suggest appropriate functions for the following tasks –
(a) To check whether the string contains digits.
(b) To find the occurrence a string within another string.
(c) To convert the first letter of a string to upper case.
(d) To convert all the letters of a string to upper case.
(f) To check whether all the letters of the string are in capital letters.
(g) to remove all the white spaces from the beginning of a string.
Ans: (a) isalnum() (b) find() (c) capitalize()
(d) upper() (f) isupper() (g) lstrip()
Q.5 Find the errors -
s=”PURA VIDA”
Print(s[9] + s[9:15])
Ans: Here the error is : Sting index out of range.
i
e et
Ans: output 1 output2
Pr
by
m
co
u.
Q.1 WAP to print following pattern without using any nested loop.
#
ib
## Ans:
R
###
on
####
#####
d
Ans:
oa
pl
U
Prepared By: Sanjeev Bhadauria & Neha Tyagi
i
e et
Pr
Q.4 WAP that:
o Prompt the user for a string
by
o Extract all the digits from the string.
If there are digits
m
o
Sum the collected digits together.
co
Printout:
u.
The digits
ib