On this page
Strings look simple until a question asks for `s[-2:1:-1]` or the output of a program that calls `replace()` and prints the original. Most lost marks come from a few rules about indexing, slicing and immutability. This post covers those rules with one example string, the methods in the syllabus, the errors students make, and a practice routine.
What does the CBSE syllabus include?
The CBSE Computer Science curriculum for 2026-27 lists strings in Class 11, Unit 2: string operations (concatenation, repetition, membership and slicing), traversing a string with loops, and these functions and methods: len(), capitalize(), title(), lower(), upper(), count(), find(), index(), endswith(), startswith(), isalnum(), isalpha(), isdigit(), islower(), isupper(), isspace(), lstrip(), rstrip(), strip(), replace(), join(), partition() and split(). Strings also return in Class 12, in text file programs. The textbook chapter is Chapter 8, Strings, in NCERT Class 11 Computer Science.
How do indexing and slicing work?
Use one string for everything: `s = "Fermi Physics"`. It has 13 characters, counting the space.
Positive indices run from 0 to 12: `s[0]` is "F", `s[6]` is "P".
Negative indices run from −1 at the end back to −13: `s[-1]` is "s".
A slice `s[start:stop:step]` starts at `start` and stops just before `stop`.
Worked examples:
`s[0:5]` gives "Fermi". Indices 0 to 4, five characters. Index 5, the space, is not included.
`s[6:]` gives "Physics". Leaving out `stop` means "to the end".
`s[-7:]` also gives "Physics". The last seven characters.
`s[::2]` gives "FriPyis". Every second character: indices 0, 2, 4, 6, 8, 10, 12.
`s[::-1]` gives "scisyhP imreF". A step of −1 walks backwards.
`s[:100]` gives the whole string with no error. The Python tutorial notes that out-of-range slice indices are handled gracefully.
But `s[20]`, a single index out of range, raises an IndexError. Slices forgive; single indices do not.
A quick check for any slice: the number of characters in `s[a:b]` is b − a, when both are in range and the step is 1.
Why can't you change a character in a string?
Strings are immutable. The Python tutorial says it directly: assigning to an indexed position raises an error. So `s[0] = "f"` gives `TypeError: 'str' object does not support item assignment`.
This is also why methods never change the original string. After `t = s.replace("Physics", "Maths")`, t is "Fermi Maths" but s is still "Fermi Physics". If you write `s.replace("Physics", "Maths")` on its own line and then print s, you get the original. To change s, write `s = s.replace(...)`.
Which methods do students confuse?
find() and index(). Both return the lowest index where a substring appears. According to the Python documentation for str, find() returns −1 when the substring is missing, while index() raises a ValueError. So `s.find("z")` is −1, but `s.index("z")` crashes.
split() and partition(). `"python is fun".split()` gives the list ['python', 'is', 'fun']. `"python is fun".partition(" ")` gives a tuple of three parts, split at the first space only: ('python', ' ', 'is fun').
join(). It is called on the separator, not the list: `"-".join(["2026", "10", "24"])` gives "2026-10-24".
title() and capitalize(). "hello world".title() gives "Hello World"; .capitalize() gives "Hello world".
isdigit() on mixed text. "123".isdigit() is True, but "12a".isdigit() is False. Every character must qualify.
strip(). It removes spaces from both ends only, not from the middle.
Which errors appear most in programs?
Adding a number to a string. `"Age: " + 16` gives a TypeError. Use `"Age: " + str(16)`.
**Confusing + and * on number strings.** `"10" + "5"` is "105", and `"10" * 3` is "101010", because these are strings, not numbers. Convert with int() first.
Case in comparisons. Checking if "Level" is a palindrome with `w == w[::-1]` gives False, because "L" and "l" differ. Compare `w.lower()` with its reverse instead.
Counting vowels without lower(). A loop that checks `ch in "aeiou"` misses capital letters. Use `"aeiouAEIOU"` or lower the string first.
Worked program: count character types
This one is on the CBSE suggested practical list.
text = input("Enter a string: ")
vowels = consonants = upper = lower = 0
for ch in text:
if ch.isalpha():
if ch.lower() in "aeiou":
vowels += 1
else:
consonants += 1
if ch.isupper():
upper += 1
else:
lower += 1
print(vowels, consonants, upper, lower)For the input "Fermi Physics", the output is 3 9 2 10: vowels e, i, i; nine consonants; F and P upper case; and ten lower-case letters. The space is skipped because `isalpha()` is False for it. Trace it by hand once, then run it to check.
A practice routine
Write a 12 to 15 character string of your own. Predict 10 slices, including two with negative steps, then check them in Python.
For each method in the syllabus list, write one line that uses it and predict the output before running.
Write the palindrome and vowel-count programs from memory, with three test cases each.
Keep an error log: index, slice, immutability, method confusion or type error.
If a slice result keeps surprising you, the Fermi Concept Library covers every concept in physics, chemistry, biology, mathematics and computing, so you can revise sequences and indexing on their own. Strings sit alongside the other sequence types in our post on lists, tuples and dictionaries, and character codes connect to binary and hexadecimal.
Right now, predict `"Fermi Physics"[-2:1:-1]`, then check it in Python.



