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:
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".
Most relevant Q&A
Chapter contents
The NCERT structure, section by section. Open a section to see its questions, then read the concept-first solution.
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.
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…
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.
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.
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:
Concatenation
To concatenate means to join. Python joins two strings end to end using the concatenation operator, written as the plus symbol +.
Repetition
Python can produce a string made of several copies of a given string using the repetition operator, written as the asterisk symbol .
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…
Slicing
Slicing is the operation that extracts a part of a string — a substring — by specifying an index range instead of a single index.
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.
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.
Handling Strings
5 QThis section brings the whole chapter together: user-defined functions that perform practical operations on strings.
+−Programs1 question
+−Programs1 question
+−Programs1 question
+−Programs1 question
Summary
- A string is a sequence of Unicode characters enclosed in single, double or triple quotes; triple-quoted strings may span multiple lines.
Exercises
+−Show 2 questionsHide questions2 questions
More questions
+−Show 5 questionsHide questions5 questions
- Q1Write a program to input line(s) of text from the user until enter is pressed. Count the total number of characters in the text (including w…Free
- Q2Write a user defined function to convert a string with more than one word into title case string where string is passed as parameter. (Title…Free
- Q3Write a function deleteChar() which takes two parameters one is a string and other is a character. The function should create a new string a…Preview
- Q4Input a string having some digits. Write a function to return the sum of digits present in this string.Preview
- Q5Write a function that takes a sentence as an input parameter where each word in the sentence is separated by a space. The function should re…Preview