Curriculum
Course: Grade XI Computer Science
Login
Text lesson

Le-8 Strings

School Revise · Class 11 Computer Science · Chapter 8

Strings

Code 083, Class 11. A string is text in quotes. Here we index and slice strings, join and repeat them, and use handy string methods.

0

index starts at zero

str

the text type

What this chapter is about

A string is a sequence of characters written in quotes. In this chapter we read parts of a string, join and repeat strings, and use built-in string methods.

1. Indexing and slicing

Each character has an index, starting at 0. s[0] is the first character and s[-1] is the last. A slice s[a:b] gives characters from a up to, but not including, b.

s = “Python” print(s[0], s[-1]) print(s[0:3]) Output: P n Pyt

2. Joining and repeating

The + sign joins (concatenates) strings and the * sign repeats a string. len(s) gives the number of characters.

3. String methods

Strings have useful methods: upper() and lower() change case, replace(x, y) swaps text, split() breaks a sentence into words, and strip() removes spaces at the ends. Strings are immutable, so a method returns a new string.

Practise with the interactive

Explore the idea by tapping. The interactive opens right here in the lesson.

Try it in the code lab

Write and run real Python right here in the lesson, then work through the practice problems with answers.

Starting Python...

Coding practice problems, with answers

Type each one into the code lab above, then open the card to see the worked solution and its output.

Problem 1. Print the length of a string.

SOLUTION

s = “Python” print(len(s))

OUTPUT

6
Problem 2. Print the first and last characters.

SOLUTION

s = “School” print(s[0], s[-1])

OUTPUT

S l
Problem 3. Convert a string to uppercase.

SOLUTION

print(“hello”.upper())

OUTPUT

HELLO
Problem 4. Join two strings with a space.

SOLUTION

a = “School” b = “Revise” print(a + ” ” + b)

OUTPUT

School Revise
Problem 5. Repeat a string three times.

SOLUTION

print(“ab” * 3)

OUTPUT

ababab
Problem 6. Print the first four characters (a slice).

SOLUTION

s = “Computer” print(s[0:4])

OUTPUT

Comp
Problem 7. Reverse a string.

SOLUTION

s = “abc” print(s[::-1])

OUTPUT

cba
Problem 8. Replace a word in a sentence.

SOLUTION

print(“I like tea”.replace(“tea”, “coffee”))

OUTPUT

I like coffee
Problem 9. Split a sentence into words.

SOLUTION

print(“one two three”.split())

OUTPUT

[‘one’, ‘two’, ‘three’]
Problem 10. Count the vowels in a string.

SOLUTION

s = “education” c = 0 for ch in s: if ch in “aeiou”: c = c + 1 print(c)

OUTPUT

5

Practice set A, multiple choice

1. In Python, the first character of a string has index …

0.

2. What does “ab” * 2 give?

abab.

3. Which method changes a string to capitals?

upper().

4. Are strings changeable (mutable) in Python?

No, strings are immutable, so methods return a new string.

Quick summary

A string is text in quotes. Indexing starts at 0, and s[-1] is the last character; a slice s[a:b] stops before b. The + sign joins strings and * repeats them, and len() counts characters. Methods like upper(), lower(), replace(), split() and strip() return new strings, because strings are immutable.

Open the Virtual Lab

These free Class 11 Computer Science notes explain strings, indexing and slicing, concatenation and repetition, and string methods with worked Python programs and practice, for CBSE students across India and the Gulf including the UAE, Saudi Arabia, Qatar, Oman, Kuwait and Bahrain.

© 2026 School Revise. All rights reserved. Original content aligned to the CBSE and NCERT Class 11 Computer Science syllabus. Unauthorised copying is not permitted.

Layer 1
Login Categories