String indexing and slicing: Class 11 practice
s[i] gives one character (index from 0; negative indices count from the end). Read the method, follow the three worked examples, then try the six questions.
What you should know first
- Strings
The idea behind string indexing and slicing
s[i] gives one character (index from 0; negative indices count from the end). s[a:b] gives characters a up to but not including b; s[a:b:k] steps by k, and s[::-1] reverses.
Step-by-step method
- Write the indices under each character.
- Include start, exclude stop.
- Apply the step (negative steps go right to left).
Worked example 1 (Basic)
s = "ALGORITHM". What is s[1:9]?
- Indices 1 to 8
- = "LGORITHM"
- Answer: "LGORITHM"
Worked example 2 (Standard)
s = "ALGORITHM". What is s[2::3]?
- Start at 2, step 3
- = "GIM"
- Answer: "GIM"
Worked example 3 (Challenge)
s = "SCIENCE". What is s[-2:] + s[:2][::-1]?
- s[-2:] = "CE"
- s[:2][::-1] = "CS"
- Answer: "CECS"
Common mistakes and misconceptions
- Including the stop index
- Counting from 1
Practice questions
- (Basic) s = "NETWORKS". What is s[2:5]?
- (Basic) s = "KEYBOARD". What is s[0:6]?
- (Standard) s = "COMPUTER". What is s[0::3]?
- (Standard) s = "COMPUTER". What is s[2::2]?
- (Challenge) s = "NETWORKS". What is s[-5:] + s[:0][::-1]?
- (Challenge) s = "ALGORITHM". What is s[-3:] + s[:2][::-1]?
Answer key with full working
- Q1: Indices 2 to 4 → = "TWO" → Answer: "TWO"
- Q2: Indices 0 to 5 → = "KEYBOA" → Answer: "KEYBOA"
- Q3: Start at 0, step 3 → = "CPE" → Answer: "CPE"
- Q4: Start at 2, step 2 → = "MUE" → Answer: "MUE"
- Q5: s[-5:] = "WORKS" → s[:0][::-1] = "" → Answer: "WORKS"
- Q6: s[-3:] = "THM" → s[:2][::-1] = "LA" → Answer: "THMLA"
Syllabus note
This skill is listed under "Strings in Python" for Class 11 in the NCERT/CBSE books. ICSE, IGCSE, IB and state boards may teach it in a different chapter or year.
Answers on this page are generated and automatically re-checked by a second, independent calculation. They have not been reviewed by a teacher — if you spot a problem, tell us on WhatsApp.
Related practice and notes
Frequently asked questions
Which chapter is string indexing and slicing in?
"Strings in Python", Class 11 Computer Science (NCERT/CBSE). Other boards may place it differently.
How were the answers checked?
Answers on this page are generated and automatically re-checked by a second, independent calculation. They have not been reviewed by a teacher — if you spot a problem, tell us on WhatsApp.