CBSE Class 11 Computer Science Chapter 12: Strings NCERT Solutions
This chapter provides essential NCERT Solutions for Class 11 Computer Science, focusing on 'Strings'. It covers fundamental string manipulation methods in Python, including capitalize(), center(), count(), decode(), encode(), endswith(), find(), and isalnum(). The solutions explain the purpose, syntax, and return values of each method with clear examples. Understanding these string operations is crucial for data processing and text manipulation in programming. These solutions are designed to help students grasp the concepts thoroughly and prepare effectively for their board examinations by offering detailed explanations and practical insights into string handling in Python.
Quick info
| Board | CBSE |
|---|---|
| Class | Class 11 |
| Subject | Computer Science |
| Session | 2026 |
| Language | English |
| Type | NCERT Solutions |
| Chapter | 12. Strings |
Chapter summary
Chapter 12, 'Strings', in the CBSE Class 11 Computer Science curriculum focuses on the fundamental concepts and methods of string manipulation in Python. The NCERT Solutions provided here detail various built-in string functions such as capitalize(), center(), count(), decode(), encode(), endswith(), find(), and isalnum(). Each solution clarifies the functionality, parameters, and output of these methods, aiding students in understanding how to effectively work with text data.
Learning outcomes
- Understand the purpose and functionality of various Python string methods.
- Learn the syntax and parameters for methods like capitalize(), center(), count(), find(), and isalnum().
- Determine the return values for string methods based on their input.
- Apply string methods to manipulate and analyze text data.
- Interpret the output of Python code involving string operations.
Topics covered
Paper topics
- String Methods
- capitalize()
- center()
- count()
- decode()
- encode()
- endswith()
- find()
- isalnum()
- String Manipulation
- Python Strings
- Text Processing
Important topics
- String Methods Overview
- capitalize() and center()
- count() and find()
- encode() and decode()
- isalnum() and endswith()
PDF preview
Read page by page below. PDF is streamed from the official NCERT website — no download button on this page.
Questions and Solutions
Question 1
Question 2
Question 3
Question 4
- width: This is a mandatory integer parameter that specifies the total length of the resulting centered string.
- fillchar: This is an optional parameter. It specifies the character to be used for padding the string on both sides to reach the desired width. If this parameter is not provided, the default padding character is a space (' ').
Question 5
Question 6
Question 7
Question 8
Question 9
Question 10
print str1.find(str2): This searches for the substring "exam" in "this is string example... ,wow!!!" starting from the beginning (index 0). The substring "exam" is found starting at index 15.print str1.find(str2, 10): This searches for "exam" starting from index 10. It is found again at index 15.print str1.find(str2, 40): This searches for "exam" starting from index 40. Since the string is shorter than index 40 and "exam" does not appear from index 40 onwards, the substring is not found. In this case, find() returns -1.
15 15 -1
Question 11
Question 12
str = "this2009"; print str.isalnum();: The string "this2009" contains only alphabetic characters ('t', 'h', 'i', 's') and numeric digits ('2', '0', '0', '9'). Since all characters are alphanumeric and the string is not empty, the isalnum() method returns True.str = "this is string example....wow!!!"; print str.isalnum();: This string contains spaces (' ') and punctuation marks ('.', '!'). These characters are not alphanumeric. Therefore, the isalnum() method returns False.
True False
Common mistakes
- Confusing the parameters and return types of different string methods.
- Incorrectly applying string methods to non-string data types.
- Misinterpreting the output of methods like find() when the substring is not present.
- Errors in understanding the default values for optional parameters in string methods.
Revision tips
- Practice using each string method with different inputs to observe their behavior.
- Pay close attention to the return values of each method (e.g., boolean, integer, new string).
- Review the syntax and parameter definitions for each method to avoid common errors.
- Work through the provided code examples and try to predict the output before checking the solution.
Practice MCQs
Q1. Which string method returns a copy of the string with only its first character capitalized?
Explanation: The capitalize() method specifically returns a copy of the string with its first character converted to uppercase and all other characters to lowercase.
Q2. What does the center() method return when used with a string?
Explanation: The center() method returns a new string that is centered within a specified width, using a given fill character for padding.
Q3. How many times does the substring 'is' occur in 'this is a test string'?
Explanation: The count() method would find 'is' twice: once in 'this' and once as the word 'is'.
Q4. Which method is used to encode a string into a specific format?
Explanation: The encode() method is used to convert a string into a sequence of bytes using a specified encoding.
Q5. What is the return value of str.find(sub) if the substring 'sub' is not found in 'str'?
Explanation: The find() method returns -1 when the specified substring is not found within the string.
Q6. The isalnum() method returns True if all characters in the string are:
Explanation: isalnum() checks if all characters in the string are either letters (a-z, A-Z) or digits (0-9).
Frequently asked questions
What is the main purpose of the Strings chapter in Class 11 Computer Science?
This chapter introduces students to the fundamental concepts of strings in Python and various built-in methods used for manipulating and processing text data effectively.
Which string method is used to check if a string ends with a specific sequence of characters?
The endswith() method is used to check if a string terminates with a specified suffix. It returns True if it does, and False otherwise.
What is the difference between encode() and decode() methods?
The encode() method converts a string into a sequence of bytes using a specified encoding, while the decode() method converts a sequence of bytes back into a string using a specified encoding.
How does the find() method work in Python strings?
The find() method searches for a specified substring within a string and returns the lowest index in the string where the substring is found. If the substring is not found, it returns -1.
Can the center() method be used without a fill character?
Yes, if the fillchar parameter is omitted, the center() method defaults to using a space character for padding.
What kind of output can be expected from the isalnum() method?
The isalnum() method returns a boolean value: True if all characters in the string are alphanumeric (letters or numbers) and the string is not empty, and False otherwise.
Content reviewed by the NCERT Help team. Editorial Team and update policy
NCERT Solutions PDF PDF on NCERT Help. URL unchanged for search indexing.