# Important Questions String Manipulation Class 11 Computer Science

Please refer to Important Questions String Manipulation Class 11 Computer Science below. These questions and answers have been prepared based on the latest examination guidelines and NCERT book issued for Class 11 Computer Science for the current academic year. We have provided Important Questions for Class 11 Computer Science for all chapters here. String Manipulation is an important chapter in Class 11 Computer Science, following Important Questions and their solutions will help you to get more marks in examinations.

## String Manipulation Class 11 Computer Science Important Questions

Question: Given a string S = “CARPE DIEM”. If n is length/2 then what would following return?
(a) S[:n] (b) S[n:] (c) S[n:n] (d) S[1:n] (e) S[n:length-1]
Ans: (a) “CARPE‖ (b) “DIEM” (c) „ ‟ (d) “ARPE” (e) “DIE”

Question: Out of the following operators, which ones can be used with strings?
=, -, *, /, //, %, >, <>, in, not in, <=
Ans: /, // and %

Question: From the string S = “CARPE DIEM”. Which ranges return “DIE” and “CAR”?
Ans: S[6:9] for ―DIE‖ and S[0:3] for ―CAR‖
Prepared By: Sanjeev Bhadauria & Neha Tyagi

Question: which of the following is not a Python legal string operation?
(a)‟abc‟+‟abc‟ (b) „abc‟*3 (c)‟abc‟ + 3 (d)‟abc‟.lower()

Question: What would following expression return?
(a) ”Hello World”.upper().lower() (b)  ”Hello World”.lower().upper()
(c) ”Hello World”.find(“Wor”,1,6) (d)  ”Hello World”.find(“Wor”)
(e) ”Hello World”.find(“wor”) (f)  ”Hello World”.isalpha()
(g) ”Hello World”.isalnum() (h)  ”Hello World”.isdigit()
(i) “123FGH”.isdigit()
(a) ‘hello world’  (b) ‘HELLO WORLD’
(c) -1                       (d) 6
(e) -1                       (f) False
(g) False                  (h) False
(i) False

Question: Write a python script that traverses through an input string and prints its characters
in different lines – two characters per line.

Question: 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.
Answer: (a) isalnum() (b) find() (c) capitalize()
(d) upper() (f) isupper() (g) lstrip()
Prepared By: Sanjeev Bhadauria & Neha Tyagi

Question: Which functions would you chose to use to remove leading and trailing white spacesfrom a given string?
Answer: Python String strip() function will remove leading and trailing whitespaces. If you want toremove only leading or trailing spaces, use lstrip() or rstrip() function instead.

Question: What is a string slice? How is it useful?
Answer: 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 the characters at indices n, n+1, n+2 . . . m-1 e.g.
‗Barabanki‘.[4:7] will return ‗ban‘.

Question: Find the output – if we give input as “Hello”

Question: Find the errors –
s=”PURA VIDA”
Print(s[9] + s[9:15])
Answer: Here the error is : Sting index out of range.

Skill Based Questions

Question: WAP to print the number of occurrences of a substring into a line.2

Question: WAP to check the given string is palindrome or not.

Q.4 WAP that:  4

• Prompt the user for a string
• Extract all the digits from the string.
• If there are digits
• Sum the collected digits together.
• Printout:
• The original string
• The digits
• The sum of the digits
• If there are no digits
• Print the original string
• A message “Has no Digits”