Python String Methods Class 11: find, count, replace, strip, split, join and isalpha Tests
Updated 17 October 2026 · Fact-checked
String methods return a NEW string (or a number, a list or True/False) and leave the original unchanged because strings are immutable. Case methods are upper(), lower(), title() and capitalize(); count() counts, find() returns the first position or -1, index() does the same but raises ValueError, replace() substitutes, strip() removes edge spaces, split() makes a list and join() builds one string from a list.
split() turns one string into a list, join() builds a new string from a list, and the original string s never changes.
Illustration drawn for QuestionBuddy.
Understand String Methods: find, count, replace, strip, split, join and the is-Tests (CBSE 11)
Case and counting. upper(), lower(), title() (first letter of every word capital), capitalize() (first letter of the whole string capital, the rest small). s.count(sub) counts non-overlapping occurrences: "banana".count("an") is 2.
Searching.
s.find(sub)returns the index of the first occurrence, or -1 if absent.s.find(sub, start)begins at index start.s.index(sub)is the same but raises ValueError if absent.s.startswith(x)ands.endswith(x)return True or False.
Testing (all return True or False). isalpha() (only letters), isdigit() (only digits), isalnum() (letters and digits only), islower(), isupper() (at least one cased letter and all cased letters match) and isspace() (only whitespace). Each returns False for the empty string. A space, a full stop or a minus sign makes isalpha, isdigit and isalnum False.
Editing (all return new strings).
strip()removes spaces from both ends;lstrip()from the left;rstrip()from the right; spaces inside stay.replace(old, new)replaces every occurrence;replace(old, new, n)replaces the first n.s.split()splits on any run of whitespace and returns a list;s.split(",")splits at each comma, so two commas in a row give an empty string "".sep.join(list)joins a list of strings with sep between them. The list must hold strings only.s.partition(sep)returns a tuple of three parts: before, the separator, after (if sep is absent, the string and two empty strings).
Immutability reminder. s.upper() alone does nothing visible; write s = s.upper() or print the result.
s = "banana"
print(s.count("an"), s.find("an"), s.find("an", 2)) # 2 1 3
print(s.replace("an", "AN")) # bANANaString Methods: find, count, replace, strip, split, join and the is-Tests (CBSE 11): key facts
- Case methods
- upper() all capital
- lower() all small
- title() each word
- capitalize() first letter only
- They return new strings.
- Search methods
- find(x) index or -1
- index(x) index or ValueError
- count(x) non-overlapping
- startswith and endswith give True or False
- find is safe for a missing value.
- Test methods
- isalpha
- isdigit
- isalnum
- islower
- isupper
- isspace
- Spaces and symbols make the first three False.
- Edit methods
- strip lstrip rstrip remove edge spaces
- replace(old, new)
- split() makes a list
- sep.join(list) makes a string
- Original string never changes.
How to answer String Methods: find, count, replace, strip, split, join and the is-Tests (CBSE 11) questions
To find the output of a method chain, apply the methods from left to right.
- 1Write the string with indices if a position or count is needed.
- 2Apply the first method and write the new string, number, list or Boolean it returns.
- 3Apply the next method to that result, not to the original string.
- 4For find, count and replace check overlapping and case; "A" and "a" are different.
- 5Write lists with square brackets and quotes, and Booleans as True or False.
String Methods: find, count, replace, strip, split, join and the is-Tests (CBSE 11) in real life
The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
Cleaning a form entry
Suppose a library form collects a name typed as " anita rao " with extra spaces and small letters.
Which methods give "Anita Rao", and what is its length?
Try it first, then show the solutionSolution
- strip() removes the edge spaces: "anita rao".
- title() makes each word start with a capital: "Anita Rao".
- The string has 5 + 1 + 3 = 9 characters.
Answer: name.strip().title() gives "Anita Rao"; length 9.
Memory hook: Clean the edges first, then fix the case.
Tricks to remember String Methods: find, count, replace, strip, split, join and the is-Tests (CBSE 11)
Short memory aids. Say each one aloud once, then use it on a question the same day.
find is polite, index is strict
find says -1 when the text is absent; index shouts ValueError.
Use it when: Choosing between them in programs.
Split and join are opposites
split cuts a string into a list; join glues a list into a string.
Use it when: Sentence and word programs.
Methods do not edit
Every method leaves s as it was; store the result if you want to keep it.
Use it when: Output questions with an unused result.
String Methods: find, count, replace, strip, split, join and the is-Tests (CBSE 11): solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: find with a missing value · 1 mark · MCQBoard level
What does "hello".find("z") return?
(a) 0
(b) -1
(c) None
(d) ValueError
Try it first, then show the solutionSolution
- find returns -1 when the text is not present.
- index() would raise ValueError, but find() does not.
Answer: (b) -1
Example 2: strip and length · 2 marks · Short answerBoard level
Give the output:
s = " Data Science "
print(len(s), s.strip(), len(s.strip()))Try it first, then show the solutionSolution
- s has 2 spaces, then "Data Science" with 12 characters (4 + 1 + 7), then 2 spaces: 16.
- strip() removes the edge spaces and gives "Data Science", whose length is 12.
- print separates the three values with spaces.
Answer: 16 Data Science 12
Example 3: Search and replace · 4 marks · Short answerHarder board level
Give the output. (4 marks)
s = "banana"
print(s.count("an"), s.find("an"), s.find("an", 2))
print(s.replace("an", "AN"))
print(s.replace("a", ""))
print(s)Try it first, then show the solutionSolution
- In "banana" (b0 a1 n2 a3 n4 a5), "an" occurs at 1 and 3, so count is 2, find is 1 and find from index 2 is 3.
- replace("an", "AN") changes both: "bANANa".
- replace("a", "") removes every a: "bnn".
- s is unchanged: banana.
Answer: 2 1 3
bANANa
bnn
banana
Example 4: split, join and partition · 5 marks · Short answerHOTS / competency
Give the output of each print. (5 marks)
line = "red,green,,blue"
parts = line.split(",")
print(parts, len(parts))
print("-".join(parts))
print("red green blue".split())
print("key=value=x".partition("="))Try it first, then show the solutionSolution
- split(",") cuts at each of the 3 commas, giving 4 parts; the two adjacent commas give an empty string: ['red', 'green', '', 'blue'] and length 4.
- "-".join(parts) places a hyphen between the parts, including the empty one: red-green--blue.
- split() with no argument treats any run of spaces as one separator: ['red', 'green', 'blue'].
- partition splits at the first "=" only: ('key', '=', 'value=x').
Answer: ['red', 'green', '', 'blue'] 4
red-green--blue
['red', 'green', 'blue']
('key', '=', 'value=x')
Example 5: Count character types · 4 marks · Short answerHarder board level
Trace the program and give its output. (4 marks)
s = "Hello World 2025!"
v = u = d = 0
for ch in s:
if ch.lower() in "aeiou":
v += 1
if ch.isupper():
u += 1
if ch.isdigit():
d += 1
print(v, u, d)Try it first, then show the solutionSolution
- Vowels in Hello World: e, o, o. So v = 3.
- Capital letters: H and W. So u = 2.
- Digits: 2, 0, 2, 5. So d = 4.
- The space and the exclamation mark add to none of the counts.
Answer: 3 2 4
Where students lose marks in String Methods: find, count, replace, strip, split, join and the is-Tests (CBSE 11)
The slips examiners see most often, and what to write instead.
Mistake: Ignoring that a method returns a new string
Writing the method call without storing or printing it.
Wrong working
s = "mango"; s.upper(); print(s) # mango
Right working
s = s.upper(); print(s) # MANGO
Do this: Assign or print the result.
Usually costs: 1 mark
Mistake: Using index() where find() is meant
Not noting the missing-value behaviour.
Wrong working
"abc".index("z") # ValueError
Right working
"abc".find("z") # -1
Do this: Use find when the text may be absent.
Usually costs: 1 mark
Mistake: Thinking isalpha() accepts spaces
Treating a phrase as letters.
Wrong working
"hello world".isalpha() is True
Right working
It is False because of the space
Do this: Any non-letter makes isalpha False.
Usually costs: 1 mark
Exam tips
- Give the return type of each method when asked to explain it: string, int, list or Boolean.
- Write the output of split() as a list with quotes around each item.
- In tracing, apply chained methods from left to right.
- Remember that title() capitalises every word but capitalize() only the first letter.
Practice questions on String Methods: find, count, replace, strip, split, join and the is-Tests (CBSE 11)
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · MCQBoard level
Which method makes the first letter of every word capital?
(a) capitalize()
(b) title()
(c) upper()
(d) swap()Hint
Every word.
Answer
(b) title()
Q2 · 1 mark · Assertion-reasonHarder board level
Assertion (A): For s = "mango", the statement s.upper() alone does not change s.
Reason (R): Strings are immutable, so string methods return new strings.
(a) Both A and R are true, and R is the correct explanation of A.
(b) Both A and R are true, but R is not the correct explanation of A.
(c) A is true, but R is false.
(d) A is false, but R is true.Hint
Return value.
Answer
(a) Both A and R are true, and R is the correct explanation of A.
Q3 · 4 marks · Short answerHarder board level
Give the output:
s = "hello world" print(s.title(), s.capitalize(), s.isalpha(), s.replace("l", "L", 2))(4 marks)
Hint
replace with a count changes only the first n matches.
Answer
title() gives Hello World; capitalize() gives Hello world; isalpha() is False because of the space; replace("l", "L", 2) changes the first two l letters (indices 2 and 3): heLLo world. Output: Hello World Hello world False heLLo world
Q4 · 3 marks · Short answerHarder board level
Give the output:
print("A123".isalnum(), "A 123".isalnum(), "123".isdigit(), "12.5".isdigit(), "abc".islower(), " ".isspace())(3 marks)
Hint
Spaces and full stops are not letters or digits.
Answer
"A123" has letters and digits only: True; "A 123" has a space: False; "123" is all digits: True; "12.5" has a full stop: False; "abc" is all small: True; " " is only whitespace: True. Output: True False True False True True
Q5 · 5 marks · Short answerHOTS / competency
Given e = "student@school.edu", write code to print the part before @, the part after @ and whether e ends with ".edu". Give the output, and say what goes wrong if the text has no @. (5 marks)
Hint
find returns -1 when absent.
Answer
i = e.find("@"); print(e[:i], e[i+1:], e.endswith(".edu")). The @ is at index 7, so e[:7] = student and e[8:] = school.edu. Output: student school.edu True. With no @, find returns -1, and e[:-1] would drop the last character, so first check that i != -1.
Test your recall
Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.
1.What does find() return for a missing value?Show answer
-1.
2.What does split() return?Show answer
A list of strings.
3.What must a list contain to be used with join()?Show answer
Strings only.
4.What does strip() remove?Show answer
Spaces at both ends of the string.
5.Does replace() change the original string?Show answer
No; it returns a new string.
String Methods: find, count, replace, strip, split, join and the is-Tests (CBSE 11): frequently asked questions
Is count() case-sensitive?
Yes; "A" and "a" are counted separately.
What does isdigit() return for an empty string?
False.
What if the separator in partition() is absent?
It returns the whole string followed by two empty strings.