TN Online TestSamacheer Kalvi practice

Strings and String Manipulation: One Mark Questions, Book Back Answers and Notes

12th Standard · Computer Science · #8

A string is a sequence of characters written inside quotes. This chapter covers creating strings, reading characters with positive and negative subscripts, why strings cannot be changed in place, slicing with a stride, the operators +, +=, * and in, formatting with % and format(), and built-in string functions.

Study this chapter

Asked in previous board exams

8 questions from this chapter came in 7 past public exams. Open any of them to see the answer and explanation.

  1. March 2026
    Which of the following operator is used for concatenation?
    See answer in the solved paper →
  2. March 2025
    The subscript of a string may be:
    See answer in the solved paper →
  3. March 2025
    Which of the following is the output of the given Python code?
    str1="Computer Science"
    print(str1[::-1])
    See answer in the solved paper →
  4. March 2024
    Which of the following is the Slicing Operator ?
    See answer in the solved paper →
  5. March 2023
    The operator which is used for concatenation ?
    See answer in the solved paper →
  6. May 2022
    What will be the output of the following code ?
    str1 = "Chennai Schools"
    str1[7] = "-"
    See answer in the solved paper →
  7. Supplementary 2021
    Strings in Python :
    See answer in the solved paper →
  8. March 2020
    What will be the output of the following code ?
    str="NEW DELHI"
    str[3]="-"
    See answer in the solved paper →

About Strings and String Manipulation

Medium ~90 min study

Names, addresses, passwords and messages are all text, and in Python text is stored as a string. Almost every program you write will read a string from the user, check it or print it in a neat layout. This chapter shows how Python stores a string and gives you the tools to work with it.

The central idea is that each character in a string has a position number called a subscript. Counting from the front starts at 0; counting from the back starts at -1. Once you are comfortable with subscripts, slicing is easy: you give a start and an end position and get the part in between. The membership operators and built-in functions such as find(), count() and upper() save you from writing a loop for every small task.

Book back questions keep returning to three points: what happens when you try to change one character (an error, because strings are immutable), the output of slices such as s[::-1] or s[2:8:2], and the result of a built-in function on a given word. Work out each slice position by position on paper and you will not lose marks here.

What you'll learn

  • Create strings with single, double and triple quotes, including multi-line strings.
  • Read any character of a string using positive or negative subscripts.
  • Predict the output of slices with start, end and stride values, including s[::-1].
  • Use +, +=, * and the membership operators in and not in on strings.
  • Format output with the % operator and the format() function.
  • Apply built-in functions such as len(), upper(), isalnum(), count() and find() to a given string.

Before you start

  • Declaring variables and assigning values in Python.
  • Basic data types such as integers and booleans.
  • while and for loops and if statements.

Topics covered in this chapter

String Immutability Characters of a string cannot be changed or deleted in place; you change the text by assigning a new string to the variable.
Subscripts Positive subscripts count from 0 at the first character; negative subscripts count from -1 at the last character.
Slicing and Stride s[start:end:stride] takes characters from start up to but not including end, moving stride positions each step; a negative stride goes backwards.
Concatenation and Repetition + joins two strings, += appends to a string variable and * repeats a string a given number of times.
Formatting with % Format codes such as %s, %d, %f and %c insert strings, integers, floats and characters into a text template.
The format() Function Curly braces {} in a string act as placeholders that format() fills with the values passed to it.
Built-in String Functions Functions such as len(), upper(), isalpha(), count() and find() for checking case, character type, occurrences and positions.

Strings and String Manipulation explained

Working with Strings in Python

Creating Strings and Immutability

A string is a sequence of Unicode characters enclosed in single, double or triple quotes. Single and double quotes work the same way. Triple quotes (''' or """) allow a string to run over several lines and keep the line breaks and spacing as typed. Strings are immutable: once created, a single character cannot be changed or deleted. If s = "Chennai", then s[0] = "K" raises a TypeError. To change the text, assign a completely new string to the variable, for example s = "Kanchi". The old string is then discarded and the variable refers to the new one.

Subscripts and Slicing

Python gives every character a subscript. Positive subscripts run from 0 for the first character to length minus 1 for the last. Negative subscripts run backwards from -1 for the last character. In "THIRUKKURAL", subscript 0 is T and -1 is L. A slice s[start:end] returns the characters from start up to, but not including, end. The optional third value, the stride, sets how many positions to move after each character is taken: s[0:10:2] takes every second character. A negative stride moves backwards, so s[::-1] gives the string reversed.

String Operators and Formatting

+ joins strings, so "Tamil" + "Nadu" gives "TamilNadu" with no space. The append operator += adds text to the end of a string variable (Python actually builds a new string and reassigns the variable). * repeats a string: "*" * 5 gives *****. The formatting operator % places values into a template using codes such as %s for a string, %d for an integer and %f for a float. The format() function uses curly braces {} as placeholders and fills them with the arguments given, in order.

Built-in Functions and Membership Operators

Python has many ready-made string functions. len() gives the length, capitalize(), upper(), lower() and swapcase() change letter case, isalpha(), isdigit() and isalnum() check the kind of characters, count() counts how often a substring occurs and find() returns the first position of a substring, or -1 if it is absent. None of these change the original string; functions that alter text return a new string. The membership operators in and not in check whether a substring is present and return True or False, as in "Nadu" in "TamilNadu".

Common mistakes to avoid

  • Trying to change one character with s[0] = 'K'. Strings are immutable, so this gives a TypeError; build a new string or use replace(), which returns a new string.
  • Using a subscript outside the valid range. For a string of length n, valid subscripts run from -n to n-1; anything else gives an IndexError.
  • Forgetting that the end value of a slice is excluded. s[0:3] gives the characters at positions 0, 1 and 2 only.
  • Trying to delete one character with del s[2], which gives a TypeError. del can only remove the whole string variable, as in del s.
  • Expecting + to add a space between words. "Tamil" + "Nadu" gives TamilNadu; write the space yourself, as in "Tamil" + " " + "Nadu".

Test yourself on these with the practice test, then check the worked reasoning in the solved MCQs.

Frequently asked questions

Can I change one character of a Python string?

No. Strings are immutable, so assigning to a subscript such as s[2] = 'x' raises a TypeError. Create a new string instead, either by slicing and joining parts of the old one or with replace(), and assign it to the variable.

What is the difference between positive and negative subscripts?

Positive subscripts count from the start: 0, 1, 2 up to length minus 1. Negative subscripts count from the end: -1 is the last character, -2 the one before it, and so on. In "PYTHON", s[0] and s[-6] are both P, and s[5] and s[-1] are both N.

How does slicing work?

s[start:end] returns the characters from position start up to, but not including, position end. If start is left out, the slice begins at the start of the string; if end is left out, it runs to the last character. For s = "COMPUTER", s[0:4] gives "COMP".

What is stride in slicing?

Stride is the optional third value in a slice. It tells Python how many positions to move after taking each character. The default is 1. With s = "COMPUTER", s[0:8:2] gives "CMUE", and a stride of -1, as in s[::-1], gives the string reversed: "RETUPMOC".

How do I remove all vowels from a string?

Start with an empty string. Loop through each character, check it with if ch not in "aeiouAEIOU", and add the character to the new string with += when it is not a vowel. You build a new string because the original cannot be changed.

What is the format() function used for?

format() inserts values into a string. The string contains curly braces {} as placeholders, and format() replaces them with its arguments in order. For example, "{} + {} = {}".format(2, 3, 5) gives "2 + 3 = 5". It avoids joining many pieces with +.

What is the difference between in and not in?

Both are membership operators. in returns True if the substring is found in the string and False otherwise. not in gives the opposite result: True only when the substring is absent. "ai" in "Chennai" is True, so "ai" not in "Chennai" is False.

Last updated 15 September 2026

More chapters in Computer Science

View all
1 Function 2 Data Abstraction 3 Scoping 4 Algorithmic Strategies 5 Python Variables and Operators 6 Control Structures 7 Python Functions 9 Lists, Tuples, Sets and Dictionary 10 Python Classes and Objects 11 Database Concepts 12 Structured Query Language (SQL) 13 Python and CSV Files 14 Importing C++ Programs in Python 15 Data Manipulation through SQL 16 Data Visualization using Pyplot: Line Chart, Pie Chart and Bar Chart