RG's E-Learning Centre · Book a free demo class · WhatsApp +91-9379416374

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

  1. Write the indices under each character.
  2. Include start, exclude stop.
  3. Apply the step (negative steps go right to left).

Worked example 1 (Basic)

s = "ALGORITHM". What is s[1:9]?

  1. Indices 1 to 8
  2. = "LGORITHM"
  3. Answer: "LGORITHM"

Worked example 2 (Standard)

s = "ALGORITHM". What is s[2::3]?

  1. Start at 2, step 3
  2. = "GIM"
  3. Answer: "GIM"

Worked example 3 (Challenge)

s = "SCIENCE". What is s[-2:] + s[:2][::-1]?

  1. s[-2:] = "CE"
  2. s[:2][::-1] = "CS"
  3. Answer: "CECS"

Common mistakes and misconceptions

  • Including the stop index
  • Counting from 1

Practice questions

  1. (Basic) s = "NETWORKS". What is s[2:5]?
  2. (Basic) s = "KEYBOARD". What is s[0:6]?
  3. (Standard) s = "COMPUTER". What is s[0::3]?
  4. (Standard) s = "COMPUTER". What is s[2::2]?
  5. (Challenge) s = "NETWORKS". What is s[-5:] + s[:0][::-1]?
  6. (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.

Book a free demo class