Skip to main content
Chapter 8 of 11
NCERT Solutions

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.

39 questions80 flashcards8 formulas & key relations5 concepts

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.

7 Questions Solved · 2 Sections

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

Let mySubject = "Computer Science".

  1. mySubject[0:len(mySubject)] gives the whole string:

Computer Science

  1. mySubject[-7:-1] means characters from index -7 to -2:

Scienc

  1. mySubject[::2] takes every 2nd character:

Cmue cec

  1. mySubject[len(mySubject)-1] gives the last character:

e

  1. 2 * mySubject repeats the string twice:

Computer ScienceComputer Science

  1. mySubject[::-2] takes every 2nd character in reverse:

ecn eurepmoC

  1. mySubject[:3] + mySubject[3:] joins the same string parts back together:

Computer Science

  1. mySubject.swapcase() changes lowercase to uppercase and uppercase to lowercase:

cOMPUTER sCIENCE

  1. mySubject.startswith('Comp') checks whether the string begins with Comp:

True

  1. 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

Let myAddress = "WZ-1,New Ganga Nagar,New Delhi".

  1. myAddress.lower() converts all letters to lowercase:

wz-1,new ganga nagar,new delhi

  1. myAddress.upper() converts all letters to uppercase:

WZ-1,NEW GANGA NAGAR,NEW DELHI

  1. myAddress.count('New') counts occurrences of New:

2

  1. myAddress.find('New') returns the first position of New.

The first New starts after WZ-1,, so index 5.

  1. myAddress.rfind('New') returns the last position of New.

The second New starts at index 21.

  1. myAddress.split(',') splits at commas:

['WZ-1', 'New Ganga Nagar', 'New Delhi']

  1. myAddress.split(' ') splits at spaces:

['WZ-1,New', 'Ganga', 'Nagar,New', 'Delhi']

  1. myAddress.replace('New','Old') replaces every New with Old:

WZ-1,Old Ganga Nagar,Old Delhi

  1. myAddress.partition(',') splits at the first comma into three parts:

('WZ-1', ',', 'New Ganga Nagar,New Delhi')

  1. myAddress.index('Agra') would raise an exception because Agra is 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

3Write a function deleteChar() which takes two parameters one is a string and other is a character. The function should create a new string after deleting all occurrences of the character from the string and return the new string.

Free with a Super Tutor account

4Input a string having some digits. Write a function to return the sum of digits present in this string.

Free with a Super Tutor account

5Write a function that takes a sentence as an input parameter where each word in the sentence is separated by a space. The function should replace each blank with a hyphen and then return the modified sentence.

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?
Key topics in Strings include String Basics and Creation, Indexing and len(), String Operations, Slicing and Reversing. Study these first, then practise questions on each for Class 11 exams.
Are these NCERT Solutions for Strings free?
The first 4 of the 7 solutions on this page are open to read. The other 3 are free with a Super Tutor account — signing up is free and needs no card.
How should I revise Strings for Class 11 exams?
Learn the core ideas first, then work through the 39 practice questions on Strings. Revise definitions regularly and use flashcards for quick recall before the exam.

Sources & Official References

Content is aligned to the official syllabus. Refer to the board website for the latest curriculum.

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.