CBSE Class 11 Computer Science Chapter 12: Strings NCERT Solutions
This chapter provides essential NCERT Solutions for Class 11 Computer Science, focusing on Chapter 12: Strings. Students will explore fundamental string manipulation methods in Python, including capitalize(), center(), count(), decode(), encode(), endswith(), find(), and isalnum(). The solutions offer clear explanations and syntax for each method, along with practical examples and outputs to solidify understanding. These solutions are designed to help students grasp the nuances of working with strings, a crucial data type in programming. By working through these detailed explanations and examples, students can effectively prepare for their examinations, ensuring a strong foundation in Python string operations.
Quick info
| Board | CBSE |
|---|---|
| Class | Class 11 |
| Subject | Computer Science |
| Session | 2026 |
| Language | English |
| Type | NCERT Solutions |
| Chapter | Chapter 12 |
Chapter summary
Chapter 12 of the CBSE Class 11 Computer Science syllabus covers the core concepts of Strings in Python. This NCERT Solutions set breaks down various string methods such as capitalize(), center(), count(), decode(), encode(), endswith(), find(), and isalnum(). It provides clear syntax, explanations, and outputs for each method, enabling students to understand how to manipulate and query strings effectively. This chapter is vital for building foundational programming skills in Python.
Learning outcomes
- Understand the purpose and syntax of Python string methods.
- Apply string methods like capitalize(), center(), and count() to manipulate strings.
- Differentiate between encode() and decode() methods for string representation.
- Utilize find() and endswith() to locate substrings within strings.
- Determine if a string consists of alphanumeric characters using isalnum().
- Interpret the output of Python code involving string methods.
Topics covered
Paper topics
- String Methods
- capitalize()
- center()
- count()
- decode()
- encode()
- endswith()
- find()
- isalnum()
- String Manipulation
- Python Strings
- String Indexing
Important topics
- String Methods Overview
- capitalize() and center()
- count() and find() for substring searching
- encode() and decode() for character encoding
- isalnum() for character type checking
- Understanding method parameters and return values
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
string.capitalize()Here, `string` refers to the string object on which the method is called. This method does not require any arguments.
Question 3
Question 4
- width: This is a mandatory integer parameter that specifies the total width of the resulting centered string.
- fillchar: This is an optional parameter that specifies the character to be used for padding. If this parameter is omitted, the default padding character is a space (' ').
Question 5
Question 6
Question 7
Question 8
Question 9
string.find(substring, start=0, end=len(string))This method searches for the `substring` within the specified `string` (or a slice defined by `start` and `end`) and returns the lowest index where the substring is found. If the substring is not found, it returns -1.
Question 10
#!/usr/bin/python str1 = "this is string example... ,wow!!!" str2 = "exam" print str1.find(str2) print str1.find(str2, 10) print str1.find(str2, 40)
15 15 -1Explanation:
- The first `print` statement searches for "exam" in `str1` from the beginning and finds it at index 15.
- The second `print` statement searches for "exam" starting from index 10 and also finds it at index 15.
- The third `print` statement searches for "exam" starting from index 40. Since "exam" does not occur at or after index 40, the method returns -1.
Question 11
string.isalnum()This method is called on a string object and does not take any arguments. It returns `True` if all characters in the string are alphanumeric (either letters or numbers) and there is at least one character, otherwise it returns `False`.
Question 12
#!/usr/bin/python str = "this2009" # No space in this string print str.isalnum() str = "this is string example....wow!!!" print str.isalnum()
True FalseExplanation:
- For the string "this2009", all characters are either letters or numbers, so `isalnum()` returns `True`.
- For the string "this is string example....wow!!!", the presence of spaces and punctuation marks means not all characters are alphanumeric, so `isalnum()` returns `False`.
Common mistakes
- Confusing the parameters and return values of string methods.
- Incorrectly applying string methods to non-string data types.
- Misinterpreting the output of find() when a substring is not present.
- Errors in understanding the encoding and decoding processes.
- Not considering the optional parameters (like beg and end) in methods like count() and find().
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., True/False, an integer, or a modified string).
- Recreate the code examples provided in the solutions to reinforce understanding.
- Focus on the difference between methods that modify strings (returning a new string) and those that return boolean values or indices.
- Understand the role of optional parameters in methods like find() and count().
Practice MCQs
Q1. Which string method returns a copy of the string with its first character capitalized?
Explanation: The capitalize() method is specifically designed to capitalize only the first character of a string and return the modified copy.
Q2. What is the primary function of the center() method in Python strings?
Explanation: The center() method pads the string with a specified fill character to center it within a given width.
Q3. The count() method returns the number of occurrences of a substring. What are its optional parameters?
Explanation: The count() method can optionally take 'beg' (start index) and 'end' (end index) parameters to specify the range for counting.
Q4. Which method is used to decode a string using a specified encoding?
Explanation: The decode() method is used to convert an encoded string back into its original string representation.
Q5. What will be the output of `str.find(substring, 10)` if the substring is found starting at index 15?
Explanation: The find() method returns the lowest index in the string where the substring is found within the specified range. If found at index 15, it returns 15.
Q6. The `isalnum()` method returns `True` if the string contains:
Explanation: isalnum() checks if all characters in the string are alphanumeric (either letters or numbers) and there is at least one character.
Frequently asked questions
What is the purpose of Chapter 12 in CBSE Class 11 Computer Science?
Chapter 12 focuses on Strings in Python, covering essential methods for manipulating and analyzing string data, which is fundamental for programming.
Which string methods are covered in these NCERT Solutions?
These solutions cover methods like capitalize(), center(), count(), decode(), encode(), endswith(), find(), and isalnum(), along with their syntax and usage.
How do these solutions help in exam preparation?
They provide clear, rewritten explanations, syntax details, and example outputs for each string method, aiding in a thorough understanding and revision for exams.
What is the difference between encode() and decode()?
encode() converts a string into a sequence of bytes using a specified encoding, while decode() converts a sequence of bytes back into a string.
What does the find() method return if the substring is not found?
If the substring is not found within the specified range, the find() method returns -1.
Can I use these solutions for practice?
Yes, the solutions include code examples and outputs that are ideal for hands-on practice to reinforce learning.
Content reviewed by the NCERT Help team. Editorial Team and update policy
NCERT Solutions PDF PDF on NCERT Help. URL unchanged for search indexing.