AmbifulWorksheets
Practice that never repeats
CBSE · Class 11 · Computer Science

Strings

Standard difficulty · 20 questions · 40 marks · Time: 37 minutes

Name: Date: Score: ____ / 40

Show your working for Sections B and C. Answers are on the last page — try every question first!

Section A — Choose the correct answer8 × 1 = 8 marks
1.
Strings in Python are:
  1. stored as numbers only
  2. limited to 255 characters
  3. mutable like lists
  4. immutable: their characters cannot be changed in place
2.
What does this program print?
s = 'banana'
print(s[-5:])
  1. banana
  2. aa
  3. nana
  4. anana
3.
What does this program print?
s = 'lamp Data'
print(s.upper())
  1. lamp Data
  2. lamp data
  3. Lamp data
  4. LAMP DATA
4.
What does this program print?
s = 'balloon'
print(s.index('l'))
  1. Error
  2. 4
  3. 3
  4. 2
5.
What does this program print?
s = 'lamp loop'
print(s.isalnum())
  1. Error
  2. True
  3. False
  4. None
6.
What does this program print?
print(', '.join('book'))
  1. k, o, o, b
  2. b, o, o, k
  3. , b, o, o, k,
  4. ['b', 'o', 'o', 'k']
7.
What does this program print?
s = 'cricket'
count = 0
for ch in s:
    if ch in 'aeiou':
        count = count + 1
print(count)
  1. 5
  2. 2
  3. 3
  4. 7
8.
What happens when this program runs?
s = 'book'
s[0] = 'X'
print(s)
  1. it stops with a TypeError, because a string cannot be changed in place
  2. it prints Xook
  3. it prints book
  4. it prints Xbook
Section B — Short answer8 × 2 = 16 marks
9.
What is meant by saying that strings are immutable? Give an example.
10.
What does this program print? Give (a) the first line (b) the second.
s = 'science'
print(s[:-4])
print(s[::-1])
11.
What does this program print? Give (a) the first line (b) the second.
s = 'computer keyboard'
print(s.count('u'))
print(s.find('te'))
12.
What does this program print? Give the three lines (a) to (c).
s = 'banana'
print(len(s))
print('anq' in s)
print(s.startswith('an'))
13.
What does this program print? Give (a) the first line (b) the second.
s = 'text;byte;note;word'
parts = s.split(';')
print(parts)
print(parts[3])
14.
This program counts characters. What are (a) u (b) l (c) d at the end?
s = 'Painting kitchen calendar 6'
u = l = d = 0
for ch in s:
    if ch.isupper():
        u = u + 1
    elif ch.islower():
        l = l + 1
    elif ch.isdigit():
        d = d + 1
print(u, l, d)
15.
What does this program print? Give (a) the first line (b) the second.
s = 'char file char'
print('::'.join(s.split()))
print(s.replace('char', 'file'))
16.
What does this program print?
s = 'program'
if s == s[::-1]:
    print('Palindrome')
else:
    print('Not a palindrome')
Section C — Word problems4 × 4 = 16 marks
17.
Explain the string operations of concatenation, repetition, membership and slicing with an example of each.
18.
What does this program print? Give the four lines (a) to (d).
s = 'sunflower picture'
print(len(s))
print(s[3:6])
print(s.count('o'))
print(s.replace('sunflower', 'new'))
19.
Trace this program. What are (a) v (b) c (c) up (d) sp at the end?
s = 'Teacher calendar 755 Language'
v = c = up = sp = 0
for ch in s:
    if ch.isalpha():
        if ch.lower() in 'aeiou':
            v = v + 1
        else:
            c = c + 1
    if ch.isupper():
        up = up + 1
    if ch.isspace():
        sp = sp + 1
print(v, c, up, sp)
20.
What does this program print?
s = 'python village mountain'
words = []
for w in s.split():
    words.append(w[::-1])
print(' '.join(words))
AmbifulWorksheets
Practice that never repeats
CBSE · Class 11 · Computer Science

Answer key

Strings · AW-11CS-STR-2026-V1 · For parents — fold back or tear off before handing the sheet to your child.

QAnswerWorking
1(d) immutable: their characters cannot be changed in place—
2(d) ananastart is included, stop is not; a negative index counts from the end
3(d) LAMP DATAupper() changes every letter to a capital
4(d) 2indexes start at 0; the first 'l' is at 2
5(c) Falseisalnum() checks every character of 'lamp loop'
6(b) b, o, o, kjoin() puts the separator between the characters
7(b) 2the vowels in 'cricket'
8(a) it stops with a TypeError, because a string cannot be changed in placestrings are immutable
9A string cannot be changed in place: s[0] = 'X' is a TypeError; a new string must be made, e.g. s = 'X' + s[1:].—
10(a) sci; (b) ecneicsindex: s0 c1 i2 e3 n4 c5 e6
11(a) 1; (b) 5count() counts; find() gives the first index
12(a) 6; (b) False; (c) Falselen() counts characters; in checks for the text; startswith() checks the beginning
13(a) ['text', 'byte', 'note', 'word']; (b) wordsplit(';') cuts at every ';'
14(a) 1; (b) 22; (c) 1spaces are none of the three
15(a) char::file::char; (b) file file filejoin() puts the separator between the parts; replace() changes every occurrence
16Not a palindromes[::-1] is 'margorp'
17'ab' + 'cd' = 'abcd'; 'ab' * 2 = 'abab'; 'b' in 'abc' is True; 'python'[1:4] = 'yth'.—
18(a) 17; (b) flo; (c) 1; (d) new picturethe space counts as a character
19(a) 10; (b) 13; (c) 2; (d) 3v: vowels, c: consonants, up: capitals, sp: spaces; digits are not letters
20nohtyp egalliv niatnuomeach word reversed, in the same order