Skip to content
← Computer Science

Computer Science · Class 11 Optional

Ch 8Strings — Class 11 Computer Science, concept-first.

A sequence in Python is an ordered collection of items in which every item sits at a definite position identified by an integer, called its index. Chapter 5 introduced the three sequence data types that Python provides:

13

Q&A

7

Concepts

~6m

Unit weightage

Start learning — read this chapter →

Key concepts

Hover a concept to preview it and jump to its most relevant Q&A.

String Variable Declaration

Imagine you have a small whiteboard. You can write a number on it, like 42. Later, you can erase it and write a name, like "Riya".

Start with this concept →

Chapter contents

The NCERT structure, section by section. Open a section to see its questions, then read the concept-first solution.

8.1

Introduction

A sequence in Python is an ordered collection of items in which every item sits at a definite position identified by an integer, called its index.

8.2

Strings

A string is a sequence built out of one or more Unicode characters. Because Unicode covers far more than the English alphabet, a character here can be anything representable in text — a letter, a digi…

8.2.1

Accessing Characters in a String

Every character inside a string occupies a numbered position, and the technique of reaching a character by its position number is called indexing.

8.2.2

String is Immutable

Strings in Python are an immutable data type. Immutable means "unchangeable": once a string has been created, its contents can never be altered.

8.3

String Operations

Because a string is a sequence of characters, Python allows a set of standard operations to be performed on string values. There are four of them, each with its own operator or notation:

8.3.1

Concatenation

To concatenate means to join. Python joins two strings end to end using the concatenation operator, written as the plus symbol +.

8.3.2

Repetition

Python can produce a string made of several copies of a given string using the repetition operator, written as the asterisk symbol .

8.3.3

Membership

Python provides two membership operators for strings: in and not in. Both take two strings and answer a yes/no question about whether the first occurs inside the second, returning a Boolean value (Tru…

8.3.4

Slicing

Slicing is the operation that extracts a part of a string — a substring — by specifying an index range instead of a single index.

8.4

Traversing a String

Traversing a string means visiting it character by character, from the first to the last, usually to examine or process each character in turn.

8.5

String Methods and Built-in Functions

Python ships with a rich set of built-in functions and methods for working with strings, so most everyday manipulations need no hand-written loop at all.

8.6

Handling Strings

5 Q

This section brings the whole chapter together: user-defined functions that perform practical operations on strings.

Summary

- A string is a sequence of Unicode characters enclosed in single, double or triple quotes; triple-quoted strings may span multiple lines.

Exercises

More questions