Computer ScienceClass 11Strings

Strings in Class 11 Computer Science: Complete NCERT Guide

By ConceptScroll Team · Published on 17 July 2026 · 5 min read

Strings are fundamental in Class 11 Computer Science, representing sequences of characters used in programming. This NCERT-based guide explains how to create, manipulate, and understand strings in Python, helping students master this essential topic.

What Are Strings? Understanding the Basics

In Class 11 Computer Science, a string is defined as a sequence of one or more Unicode characters. These characters can be letters, digits, spaces, or special symbols. Python, the programming language used in NCERT, allows strings to be created by enclosing characters within:

  • Single quotes: 'Hello'
  • Double quotes: "Hello"
  • Triple quotes: '''Hello''' or """Hello"""

Triple quotes are especially useful for writing strings that span multiple lines, such as documentation or long text blocks.

Unlike some languages, Python does not have a separate character data type. A string of length one is treated as a character. For example, 'A' is a string but can be considered a character.

Example: ``python str1 = 'Hello World!' str2 = "Hello World!" str3 = '''Hello World!''' str4 = """Hello World!""" `` All these variables hold the same string value.

Understanding what strings are is the first step to mastering their use in programming.

Creating and Representing Strings in Python

Creating strings in Python is straightforward. You can use different types of quotes depending on your needs:

  • Single quotes (' '): Useful for short strings.
  • Double quotes (" "): Handy when the string contains single quotes.
  • Triple quotes (''' ''' or """ """): Allow multi-line strings without escape characters.

Example: ``python multi_line = '''This is a multi-line string.''' print(multi_line) ` Output: ` This is a multi-line string. ``

This flexibility helps in writing readable and maintainable code, especially when dealing with large text blocks or documentation.

Quote TypeUsageExample
Single (' ')Simple strings without quotes'Python'
Double (" )Strings with single quotes"It's easy"
Triple (''' ''')Multi-line or doc strings'''Line1\nLine2'''

Remember, all these methods create immutable string objects.

Want to test yourself on Strings? Try our free quiz →

Properties of Strings: Immutability and Indexing

Strings in Python are immutable, meaning once created, their contents cannot be changed. If you try to modify a character in a string, Python will raise an error.

Example: ``python s = "Hello" s[0] = 'h' # This will cause an error ``

To change a string, you must create a new string.

Indexing allows you to access individual characters in a string using their position (index). Python uses zero-based indexing:

  • s[0] gives the first character.
  • Negative indices count from the end, e.g., s[-1] is the last character.

Slicing lets you extract substrings:

  • s[start:end] extracts characters from index start up to but not including end.
  • s[start:end:step] extracts characters with a step value.

Example: ``python mySubject = "Computer Science" print(mySubject[0:8]) # Output: Computer print(mySubject[-7:-1]) # Output: Scienc print(mySubject[::2]) # Output: Cmue cne print(mySubject[::-1]) # Output: ecneicS retupmoC ``

Understanding immutability and indexing is essential for manipulating strings effectively.

Common String Operations and Methods

Python provides many built-in methods to perform operations on strings. Here are some frequently used ones:

  • lower(): Converts all characters to lowercase.
  • upper(): Converts all characters to uppercase.
  • count(substring): Counts occurrences of a substring.
  • find(substring): Returns the index of the first occurrence of a substring or -1 if not found.
  • replace(old, new): Replaces occurrences of old substring with new.
  • split(separator): Splits the string into a list based on the separator.
  • startswith(prefix): Checks if the string starts with a given prefix.

Example: ``python myAddress = "WZ-1, New Ganga Nagar, New Delhi" print(myAddress.lower()) # Output: wz-1, new ganga nagar, new delhi print(myAddress.upper()) # Output: WZ-1, NEW GANGA NAGAR, NEW DELHI print(myAddress.count('New')) # Output: 2 print(myAddress.find('New')) # Output: 5 print(myAddress.replace('New', 'Old')) # Output: WZ-1, Old Ganga Nagar, Old Delhi print(myAddress.split(',')) # Output: ['WZ-1', ' New Ganga Nagar', ' New Delhi'] print(myAddress.startswith('WZ')) # Output: True ``

These methods help you manipulate and analyze strings efficiently in your programs.

Working with Strings: Examples and Practice

Let's solve a few examples to understand string operations better.

Example 1: Extract a substring ``python mySubject = "Computer Science" # Extract 'Science' print(mySubject[-7:]) # Output: Science ``

Example 2: Reverse a string ``python text = "Python" print(text[::-1]) # Output: nohtyP ``

Example 3: Repeat a string ``python repeat = "Hi! " print(3 * repeat) # Output: Hi! Hi! Hi! ``

Example 4: Swap case ``python s = "Hello World" print(s.swapcase()) # Output: hELLO wORLD ``

Practicing such examples will prepare you for NCERT exercises and exams.

Comparison of String Methods: Quick Reference Table

Here is a quick comparison of some popular string methods useful for Class 11 students:

MethodPurposeExampleOutput
lower()Convert to lowercase'Hello'.lower()'hello'
upper()Convert to uppercase'Hello'.upper()'HELLO'
count(sub)Count occurrences of substring'banana'.count('a')3
find(sub)Find first index of substring'banana'.find('na')2
replace(old,new)Replace substring'apple'.replace('p','b')'abble'
split(sep)Split string into list'a,b,c'.split(',')['a','b','c']
startswith(pref)Check prefix'apple'.startswith('ap')True

Use this table as a quick guide for your programming assignments and exam preparation.

Frequently asked questions

What is a string in Class 11 Computer Science?

A string is a sequence of Unicode characters enclosed in quotes, used to store text.

How do you create multi-line strings in Python?

Use triple quotes (''' ''' or """ """) to create strings spanning multiple lines.

Are strings mutable or immutable in Python?

Strings are immutable; their contents cannot be changed after creation.

How can you access individual characters in a string?

By using indexing with square brackets, e.g., string[0] for the first character.

What does the string method `find()` do?

find() returns the index of the first occurrence of a substring or -1 if not found.

Can strings be concatenated or repeated in Python?

Yes, use + to concatenate and * to repeat strings multiple times.

Ready to ace this chapter?

Get the full Strings chapter — interactive notes, diagrams, worked solutions, polls and a free practice quiz — in the ConceptScroll app.

Open in ConceptScroll →

Study smarter with ConceptScroll

Daily NCERT-aligned reels, AI doubt solving and chapter quizzes — all free.

Start learning free
#class 11#computer science#immutability#indexing#ncert#programming#python#string methods#strings

Continue reading