Strings — NCERT Solutions
CBSE · Class 11 · Computer Science
NCERT question answers for Strings, CBSE Class 11 Computer Science: 7 textbook questions solved step by step. Covers Exercise and Programming Problems.
Interactive on Super Tutor
Studying Strings? Get the full interactive chapter.
Quizzes, flashcards, AI doubt-solver and a step-by-step study plan — built for NCERT solutions and more.
Free trial, no card needed.
The first 4 solutions are open to read. The other 3 are free with a Super Tutor account. Unlock all 7 free in Super Tutor
Exercise
1Consider the following string mySubject:
mySubject = "Computer Science"
What will be the output of the following string operations :i. print(mySubject[0:len(mySubject)])
ii. print(mySubject[-7:-1])
iii. print(mySubject[::2])
iv. print(mySubject[len(mySubject)-1])
v. print(2*mySubject)
vi. print(mySubject[::-2])
vii. print(mySubject[:3] + mySubject[3:])
viii. print(mySubject.swapcase())
ix. print(mySubject.startswith('Comp'))
x. print(mySubject.isalpha())
Show solution
i. print(mySubject[0:len(mySubject)])
ii. print(mySubject[-7:-1])
iii. print(mySubject[::2])
iv. print(mySubject[len(mySubject)-1])
v. print(2*mySubject)
vi. print(mySubject[::-2])
vii. print(mySubject[:3] + mySubject[3:])
viii. print(mySubject.swapcase())
ix. print(mySubject.startswith('Comp'))
x. print(mySubject.isalpha())
Let mySubject = "Computer Science".
mySubject[0:len(mySubject)]gives the whole string:
Computer Science
mySubject[-7:-1]means characters from index-7to-2:
Scienc
mySubject[::2]takes every 2nd character:
Cmue cec
mySubject[len(mySubject)-1]gives the last character:
e
2 * mySubjectrepeats the string twice:
Computer ScienceComputer Science
mySubject[::-2]takes every 2nd character in reverse:
ecn eurepmoC
mySubject[:3] + mySubject[3:]joins the same string parts back together:
Computer Science
mySubject.swapcase()changes lowercase to uppercase and uppercase to lowercase:
cOMPUTER sCIENCE
mySubject.startswith('Comp')checks whether the string begins withComp:
True
mySubject.isalpha()is False because the string contains a space.
So the outputs are as above, in order.
Not sure why a step works? check your working in Super Tutor
2Consider the following string myAddress:
myAddress = "WZ-1,New Ganga Nagar,New Delhi"
What will be the output of following string operations :i. print(myAddress.lower())
ii. print(myAddress.upper())
iii. print(myAddress.count('New'))
iv. print(myAddress.find('New'))
v. print(myAddress.rfind('New'))
vi. print(myAddress.split(','))
vii. print(myAddress.split(' ''))
viii. print(myAddress.replace('New','Old'))
ix. print(myAddress.partition(','))
x. print(myAddress.index('Agra'))
Show solution
i. print(myAddress.lower())
ii. print(myAddress.upper())
iii. print(myAddress.count('New'))
iv. print(myAddress.find('New'))
v. print(myAddress.rfind('New'))
vi. print(myAddress.split(','))
vii. print(myAddress.split(' ''))
viii. print(myAddress.replace('New','Old'))
ix. print(myAddress.partition(','))
x. print(myAddress.index('Agra'))
Let myAddress = "WZ-1,New Ganga Nagar,New Delhi".
myAddress.lower()converts all letters to lowercase:
wz-1,new ganga nagar,new delhi
myAddress.upper()converts all letters to uppercase:
WZ-1,NEW GANGA NAGAR,NEW DELHI
myAddress.count('New')counts occurrences ofNew:
2
myAddress.find('New')returns the first position ofNew.
The first New starts after WZ-1,, so index 5.
myAddress.rfind('New')returns the last position ofNew.
The second New starts at index 21.
myAddress.split(',')splits at commas:
['WZ-1', 'New Ganga Nagar', 'New Delhi']
myAddress.split(' ')splits at spaces:
['WZ-1,New', 'Ganga', 'Nagar,New', 'Delhi']
myAddress.replace('New','Old')replaces everyNewwithOld:
WZ-1,Old Ganga Nagar,Old Delhi
myAddress.partition(',')splits at the first comma into three parts:
('WZ-1', ',', 'New Ganga Nagar,New Delhi')
myAddress.index('Agra')would raise an exception becauseAgrais not present.
So the output is ValueError: substring not found.
Not sure why a step works? check your working in Super Tutor
Programming Problems
1Write a program to input line(s) of text from the user until enter is pressed. Count the total number of characters in the text (including white spaces), total number of alphabets, total number of digits, total number of special symbols and total number of words in the given text. (Assume that each word is separated by one space).Show solution
text = input("Enter text: ")
chars = len(text)
alphabets = 0
digits = 0
special = 0
words = 0
for ch in text:
if ch.isalpha():
alphabets += 1
elif ch.isdigit():
digits += 1
elif ch != ' ':
special += 1
if text != '':
words = text.count(' ') + 1
print("Total characters:", chars)
print("Total alphabets:", alphabets)
print("Total digits:", digits)
print("Total special symbols:", special)
print("Total words:", words)Not sure why a step works? check your working in Super Tutor
2Write a user defined function to convert a string with more than one word into title case string where string is passed as parameter. (Title case means that the first letter of each word is capitalised)Show solution
def titleCase(st):
newstr = ''
word = ''
for ch in st:
if ch == ' ':
newstr += word.capitalize() + ' '
word = ''
else:
word += ch
newstr += word.capitalize()
return newstr
st = input("Enter a string: ")
print(titleCase(st))Not sure why a step works? check your working in Super Tutor
Free with a Super Tutor account
Free with a Super Tutor account
Free with a Super Tutor account
3 more solved questions in Strings
They are free with a Super Tutor account, along with practice quizzes and flashcards for this chapter. Free to start, no card needed.
Frequently Asked Questions
What are the important topics in Strings for CBSE Class 11 Computer Science?
Are these NCERT Solutions for Strings free?
How should I revise Strings for Class 11 exams?
Sources & Official References
- NCERT Official — ncert.nic.in
- CBSE Academic — cbseacademic.nic.in
- CBSE Official — cbse.gov.in
- National Education Policy 2020 — education.gov.in
Content is aligned to the official syllabus. Refer to the board website for the latest curriculum.
More resources for Strings
Practice Quiz
Test yourself with a quick quiz
Important Questions
Exam-style questions with answers
Revision Notes
Key points for last-minute revision
Formula Sheet
The chapter's formulas in one place
Chapter Summary
Understand the chapter at a glance
Concept Maps
See how topics connect
Study Plan
Step-by-step plan for this chapter
Flashcards
Quick-fire cards for active recall
Syllabus
What topics to cover
For serious students
Get the full Strings chapter — start free.
Quizzes, flashcards, an AI doubt solver and a study plan for CBSE Class 11 Computer Science. Free to start, no card needed.