Samacheer Kalvi Class 12 Computer Science Solutions Chapter 8 Strings and String Manipulations

Get the most accurate TN Board Solutions for Class 12 Computer Science Chapter 08 Strings and String Manipulations here. Updated for the 2026-27 academic session, these solutions are based on the latest TN Board textbooks for Class 12 Computer Science. Our expert-created answers for Class 12 Computer Science are available for free download in PDF format.

Detailed Chapter 08 Strings and String Manipulations TN Board Solutions for Class 12 Computer Science

For Class 12 students, solving TN Board textbook questions is the most effective way to build a strong conceptual foundation. Our Class 12 Computer Science solutions follow a detailed, step-by-step approach to ensure you understand the logic behind every answer. Practicing these Chapter 08 Strings and String Manipulations solutions will improve your exam performance.

Class 12 Computer Science Chapter 08 Strings and String Manipulations TN Board Solutions PDF

I. Choose the best answer (1 Marks)

 

Question 1. str1="TamilNadu"
print(str1[::-1])

(a) Tamilnadu
(b) Tmlau
(c) udanlimaT
(d) udaNlimaT
Answer: (d) udaNlimaT
In simple words: This code reverses the string `str1` and prints it. The `[::-1]` part creates a reversed copy of the string. So, "TamilNadu" becomes "udaNlimaT".

🎯 Exam Tip: Remember that `[::-1]` is a common Python trick to reverse sequences like strings or lists. The general slice `[start:end:step]` lets you control which parts of a sequence are included and in what order.

 

Question 2. What will be the output of the following code?
str1 = "Chennai Schools"
str1[7] =

(a) Chennai-Schools
(b) Chenna-School
(c) Type error
(d) Chennai
Answer: (a) Chennai-Schools
In simple words: This question might be showing an incomplete code snippet or a concept where a string character is being referenced in a way that relates to the whole string output. In general Python, directly assigning to a string index like `str1[7] =` would cause an error because strings cannot be changed after they are made. However, following the given answer, we assume the intended output relates to the original string content in some way.

🎯 Exam Tip: Be careful with string immutability in Python; you cannot change individual characters in a string. To make changes, you usually create a new string based on the old one.

 

Question 3. Which of the following operator is used for concatenation?
(a) +
(b) &
(c) *
(d) =
Answer: (a) +
In simple words: In Python, the plus sign `+` is used to join two or more strings together, which is called concatenation. It simply puts one string after another.

🎯 Exam Tip: The `+` operator works for both numbers (addition) and strings (concatenation), so always check the data types you are using. Remember that `*` is used for repeating a string.

 

Question 4. Defining strings within triple quotes allows creating:
(a) Single line Strings
(b) Multiline Strings
(c) Double line Strings
(d) Multiple Strings
Answer: (b) Multiline Strings
In simple words: When you use three single quotes or three double quotes (`'''...'''` or `"""..."""`) to define a string, you can write the string across many lines without needing special characters like `\n`. This makes it easy to store long blocks of text.

🎯 Exam Tip: Triple quotes are great for documentation strings (docstrings) for functions and modules, or for storing paragraphs of text. Always use them when your string content spans multiple lines for better readability.

 

Question 5. Strings in python:
(a) Changeable
(b) Mutable
(c) Immutable
(d) flexible
Answer: (c) Immutable
In simple words: Python strings are "immutable," which means you cannot change them after they have been created. If you want to change a string, you actually have to make a brand new string with the desired changes.

🎯 Exam Tip: Understanding immutability is crucial. It means operations like `str1[0] = 'a'` are not allowed. You must use methods like string slicing and concatenation to create a modified version, for example, `new_str = 'a' + str1[1:]`.

 

Question 6. Which of the following is the slicing operator?
(a) {}
(b) []
(c) <>
(d) ()
Answer: (b) []
In simple words: To get a part of a string, or a "slice," you use square brackets `[]` along with index numbers. This allows you to pick out specific characters or sections of the string.

🎯 Exam Tip: Square brackets `[]` are also used for accessing individual characters by their index (e.g., `my_string[0]`). For slicing, you use a colon inside the brackets, like `my_string[start:end]`, to specify a range.

 

Question 7. What is stride?
(a) index value of slide operation
(b) first argument of slice operation
(c) the second argument of slice operation
(d) third argument of slice operation
Answer: (d) third argument of slice operation
In simple words: When you slice a string, you can give a third number called the 'stride'. This number tells Python how many characters to skip forward after taking each character from the slice. It controls the step size.

🎯 Exam Tip: The format for slicing with stride is `[start:end:step]`. If `step` is not given, it defaults to 1. A negative step reverses the string and changes the meaning of `start` and `end`.

 

Question 8. Which of the following formatting character is used to print exponential notation in the upper case?
(a) %e
(b) %E
(c) %g
(d) %n
Answer: (a) %e
In simple words: In string formatting, `%e` is used to show a number in scientific notation, which means it uses 'e' to represent "times 10 to the power of". Although `%E` is typically used for uppercase 'E' in exponential notation, according to the provided answer, `%e` is selected.

🎯 Exam Tip: It is good practice to test format specifiers with example numbers to understand their exact output, especially when dealing with case sensitivity in exponential notation.

 

Question 9. Which of the following is used as placeholders or replacement fields which get replaced along with the format() function?
(a) {}
(b) <>
(c) ++
(d) ^^
Answer: (a) {}
In simple words: When you use the `format()` function in Python to put values into a string, you use curly braces `{}` inside the string as a special marker. These braces show where your values will be placed.

🎯 Exam Tip: Curly braces `{}` are essential for `str.format()` and f-strings (formatted string literals). They indicate where variables or expressions should be inserted into the string, making dynamic string creation very clear.

 

Question 10. The subscript of a string may be:
(a) Positive
(b) Negative
(c) Both (a) and (b)
(d) Either (a) or (b)
Answer: (d) Either (a) or (b)
In simple words: You can use both positive and negative numbers to refer to characters in a string. Positive numbers count from the beginning (starting at 0), and negative numbers count from the end (starting at -1).

🎯 Exam Tip: Remember that positive indices start from 0 for the first character, while negative indices start from -1 for the last character. Both are useful for different string access patterns.

II. Answer the following questions (2 Marks)

 

Question 1. What is String?
Answer: A string is a basic data type in Python that is used to manage a sequence of characters. It is made up of Unicode characters and can include letters, numbers, or special symbols. Strings must be enclosed within single, double, or even triple quotes. For example: 'Welcome to learning Python', "Welcome to learning Python", or β€œWelcome to learning Python”.
In simple words: A string is a series of letters, numbers, or symbols in Python, like a word or sentence. You need to put quotes around it.

🎯 Exam Tip: Always remember to enclose strings in quotes (single, double, or triple) in Python. Using the correct type of quotes is important, especially when a string itself contains quotes.

 

Question 2. Do you modify a string in Python?
Answer: No, you cannot directly modify a string in Python once it has been created. This is because strings are immutable. This means that if you try to change a character or delete a part of an existing string, it is not allowed. Instead, if you want to "modify" a string, you must create a brand new string value and assign it to the same or a different variable. The original string remains unchanged.
In simple words: No, you cannot change a string once it's made in Python. If you want a different string, you have to create a new one.

🎯 Exam Tip: Python strings being immutable means that operations like `str[index] = new_char` will cause an error. Instead, create new strings using slicing and concatenation to achieve modifications.

 

Question 3. How will you delete a string in Python?
Answer: Python does not allow you to delete a specific character from a string because strings are immutable. However, you can remove an entire string variable from memory by using the `del` command. For instance, if you have `str1="How about you"`, you can print it, then use `del str1` to delete the variable. After deletion, trying to print `str1` again will result in a `NameError` because the variable no longer exists.
In simple words: You can't delete just one character from a Python string. But you can use the `del` command to remove the whole string variable from your program.

🎯 Exam Tip: The `del` keyword is used for deleting variables, not just string variables. It removes the name from the namespace, making the object it referred to eligible for garbage collection.

 

Question 4. What will be the output of the following python code?
str1 = "School"
print(str1*3)

Answer: The code `str1 = "School"` assigns the string "School" to the variable `str1`. The expression `str1*3` uses the multiplication operator, which, when applied to a string, repeats the string three times. So, the output will be:
Output:
School School School
In simple words: The code will print the word "School" repeated three times right next to each other.

🎯 Exam Tip: The `*` operator is very useful for repeating patterns or creating separator lines. Remember that it concatenates the string with itself the specified number of times.

 

Question 5. What is slicing?
Answer: String slicing refers to the process of extracting a part, or a "substring," from a main string. You can get a substring from the original string by using the square bracket `[]` operator along with index or subscript values. Therefore, `[]` is also known as the slicing operator. Using this operator, you can select one or more specific parts of a string. The general format for string slicing is `str[start:end]`. Here, `start` is the index where the slice begins, and `end` is the index where it stops. Python includes the character at the `start` index but excludes the character at the `end` index, effectively taking characters up to `end-1`. For example, to get the first 4 characters (from index 0 to 3), you would specify `[0:4]`. If you want to slice a single character from a string, like the first character of "THIRUKKURAL", you would use `str1[0]`, which outputs 'T'.
In simple words: Slicing means taking a small piece or section out of a longer string. You use square brackets and numbers to tell Python which part you want.

🎯 Exam Tip: When slicing, remember that the `end` index is always exclusive. If `start` or `end` are omitted, they default to the beginning or end of the string respectively. For instance, `str[:end]` slices from the start, and `str[start:]` slices to the end.

III. Answer the following questions (3 Marks)

 

Question 1. Write a Python program to display the given pattern
COMPUTER
COMPUTE
COMPUT
COMPU
COMP
COM
CO
C
Coding:
str1="COMPUTER"
index=len(str1)
for i in str1:
print(str1[0:index])
index-=1

Answer: The Python program aims to print the word "COMPUTER" in a decreasing letter pattern. It starts by assigning "COMPUTER" to `str1` and calculating its length. Then, it uses a loop to print slices of `str1`, reducing the `index` by 1 in each step. This process creates the desired pattern by progressively shortening the printed part of the string. The expected output is:
COMPUTER
COMPUTE
COMPUT
COMPU
COMP
COM
CO
C
In simple words: This program takes the word "COMPUTER" and prints it, then prints it again but missing the last letter, and keeps doing this until only the first letter is left.

🎯 Exam Tip: This pattern demonstrates string slicing and loops effectively. Pay attention to how the `index` variable controls the length of the slice `str1[0:index]` in each iteration.

 

Question 2. Write a short note about the following with suitable example:
(a) capitalize()
(b) swapcase()

Answer:
(a) **Function: capitalize()**
Syntax: `string.capitalize()`
Description: This function is used to change the first character of a string to an uppercase letter, while all other characters in the string are converted to lowercase. This is useful for standardizing text formatting.
Example:
`>>>city="chennai”`
`>>>print(city.capitalize())`
`Chennai`
(b) **Function: swapcase()**
Syntax: `string.swapcase()`
Description: This function converts all uppercase letters in a string to lowercase and all lowercase letters to uppercase. It "swaps" the case of every character within the string. Numbers and symbols remain unchanged.
Example:
`>>>str1="tAmil.NaDu”`
`>>>print(str1.swapcase())`
`TaMlInAdU`
In simple words: `capitalize()` makes the very first letter of a word big and the rest small. `swapcase()` flips every letter's case - big letters become small, and small letters become big.

🎯 Exam Tip: Remember that `capitalize()` only affects the *first* character, converting all subsequent characters to lowercase. `swapcase()`, on the other hand, changes the case of *every* letter it finds.

 

Question 3. What will be the output of the given python program?
str1 = "welcome"
str2 = "to school"
str3=str1[:2]+str2[len(str2)-2:] print(str3)

Answer: The program first defines two strings, `str1` as "welcome" and `str2` as "to school". Then, it creates `str3` by combining parts of `str1` and `str2`. `str1[:2]` takes the first two characters of `str1` ("we"). `len(str2)` calculates the length of `str2` (which is 9). So, `len(str2)-2:` becomes `9-2:` or `7:`, which means slicing `str2` from index 7 to the end. `str2[7:]` takes "ol" from "to school". Finally, these two parts are joined to form "weol". The program prints `str3`.
Output:
weol
In simple words: The code takes the first two letters from "welcome" ("we") and the last two letters from "to school" ("ol"), then puts them together to make "weol" and prints it.

🎯 Exam Tip: This question tests your understanding of string slicing, string length (`len()`), and string concatenation. Pay close attention to inclusive and exclusive indices in slicing, and how negative indices or `len()` can be used to reference parts of a string from the end.

 

Question 4. What is the use of format()? Give an example.
Answer: The `format()` function is a very adaptable and strong tool used with strings for formatting them in Python. It allows you to build strings dynamically by inserting values into predefined placeholders. The curly braces `{}` act as these placeholders or replacement fields inside the string, and they are filled with values provided to the `format()` function. This makes it easy to create well-structured output, especially when dealing with numerical data or user input.
Example:
`num1 = int(input("Number 1: "))`
`num2 = int(input("Number 2: "))`
`print("The sum of {} and {} is {}".format(num1, num2,(num1 + num2)))`
Output (if user enters 34 and 54):
Number 1: 34
Number 2: 54
The sum of 34 and 54 is 88.
In simple words: The `format()` function helps you put values into a string easily. You use `{}` in your string where you want the values to go.

🎯 Exam Tip: `format()` is very flexible; you can specify order, add formatting (like decimal places or padding), and even refer to arguments by name inside the curly braces. It is a powerful method for controlled string output.

 

Question 5. Write a note about count() function in python.
Answer:
**Function:** `count()`
**Syntax:** `string.count(substring, start, end)`
**Description:**
* The `count()` function returns the number of times a specified `substring` appears within a given `string`.
* The `substring` can be a single character or a longer sequence of characters.
* The `start` and `end` arguments are optional. If they are not provided, Python searches the `substring` throughout the entire string. If provided, the search is limited to the slice `string[start:end]`.
* The search is case-sensitive, meaning 'a' is different from 'A'.
Example:
`>>>str1="Raja RajaChozhan"`
`>>>print(str1.count('Raja'))`
`2`
`>>>print(str1.count('r'))`
`0`
`>>>print(str1.count('R'))`
`2`
`>>>print(str1.count('a'))`
`5`
`>>>print(str1.count('a',0,5))`
(This example has a slight variation where 'a' is searched from index 0 up to, but not including, index 5.)
`2`
`>>>print(str1.count('a',11))`
(This example searches for 'a' from index 11 to the end of the string.)
`2`
In simple words: The `count()` function tells you how many times a small piece of text (or even one letter) appears inside a bigger piece of text. You can also tell it to only look in a certain part of the text.

🎯 Exam Tip: Remember that `count()` is case-sensitive, so 'apple'.count('A') will be 0. Also, `start` and `end` define a slice within which the count is performed, similar to string slicing behavior.

IV. Answer the following questions (5 Marks)

 

Question 1. Explain string operators in python with suitable examples.
Answer:
String Operators: Python offers several operators that are very useful for performing various operations on strings. These operators help in manipulating strings, such as joining them, repeating them, or appending to them. Here are some of the key string operators:

(i) **Concatenation (+):**
Concatenation is the process of joining two or more strings together to form a single, longer string. In Python, the plus sign `+` operator is used for this purpose.
Example:
`>>> "welcome" + "Python"`
`'welcomePython'`

(ii) **Append (+=):**
Appending means adding more strings to the end of an already existing string. The `+=` operator is specifically used to append a new string to an existing string variable, effectively updating the variable with the longer string. This is a shortcut for `str1 = str1 + "new string"`.
Example:
`>>> str1 = "Welcome to "`
`>>> str1+="Learn Python"`
`>>> print(str1)`
`Welcome to Learn Python`

(iii) **Repeating (*):**
The multiplication operator `*` is used to display a string multiple times. When you multiply a string by an integer, the string is repeated that many times, creating a new string that is the original string concatenated with itself repeatedly.
Example:
`>>> print("Hello" * 3)`
`HelloHelloHello`

(iv) **String slicing:**
String slicing allows you to extract a "slice" or a portion (substring) from a main string. This is done using the square bracket `[]` operator along with index or subscript values. Therefore, `[]` is also known as the slicing operator. You can use it to get one or more substrings from the main string. The general format for a slice operation is `str[start:end]`. The `start` is the beginning index, and `end` is the index where the slice stops (the character at `end` is not included). Python considers the end value to be one less than the actual index specified (i.e., `n-1`). For instance, to get the first 4 characters of a string, you would specify `0` to `4` (meaning `str[0:4]`).
Example: slice a single character from a string
`>>> str1="THIRUKKURAL"`
`>>> print(str1[0])`
`T`

(v) **Stride when slicing string:**
When performing a slicing operation, you can include a third argument, called the `stride`. The stride determines how many characters to move forward after selecting the first character. It essentially dictates the step size when taking characters from the string. If no stride is specified, the default value is `1`. A negative stride value can be used to iterate through the string in reverse order.
Example:
`>>> str1 = "Welcome to learn Python"`
`>>> print(str1[10:16])`
`learn`
`>>> print(str1[::-2])`
`nhy re teolW`
This shows slicing from index 10 to 16, which is "learn". The second example `[::-2]` reverses the string and then takes every second character.
In simple words: String operators help us play with strings. `+` joins strings, `+=` adds to an existing string, `*` repeats a string many times, and `[]` lets us pick out parts of a string using 'slicing', where 'stride' can control the step size.

🎯 Exam Tip: Be sure to distinguish between operators that create new strings (like `+` and `*`) and string methods (like `capitalize()` or `count()`). Understand that `+=` is a shorthand assignment operator.

I. Choose the best answer (1 Mark)

 

Question 1. Strings in Python can be created using quotes
(a) Single
(b) Double
(c) Triple
(d) All of the options
Answer: (d) All of the options
In simple words: In Python, you can make strings by putting your text inside single quotes, double quotes, or even three quotes of either type. All these ways work.

🎯 Exam Tip: While all quote types work, choose one style (e.g., single quotes) for consistency in your code, but know that triple quotes are especially useful for multiline strings or docstrings.

 

Question 2. Strings are enclosed with
(a) "
(b) ""
(c) """
(d) all of these
Answer: (d) all of these
In simple words: Python allows strings to be wrapped in single quotes, double quotes, or triple quotes (either single or double type). So, all these options are valid ways to define a string.

🎯 Exam Tip: Using different types of quotes can be handy when your string itself contains quotes. For example, if your string has a single quote, you can enclose it in double quotes.

 

Question 3. The positive subscript of the string starts from and ends with
Answer: The positive subscript of a string starts from `0` (for the first character) and ends with `n - 1`, where `n` is the total number of characters in the string. This means the last character is at index `n-1`.
In simple words: When counting from the start of a string, the first character is number 0, and the very last character is one less than the total length of the string.

🎯 Exam Tip: Always remember that Python uses zero-based indexing. This means the first element is at index 0, and the last element of a sequence with 'n' items is at index 'n-1'.

 

Question 4. Another name of String index values are
(a) class
(b) subscript
(c) function
(d) arguments
Answer: (b) subscript
In simple words: The numbers you use to point to specific characters in a string are also called 'subscripts'. They help you find each character.

🎯 Exam Tip: While 'index' is commonly used, 'subscript' is also a correct and interchangeable term, especially in formal contexts, for referring to the position of an element within a sequence.

 

Question 5. Which of the following is used to access and manipulate the strings
(a) Index value
(b) Subscript
(c) Parameters
(d) a or b
Answer: (d) a or b
In simple words: To reach and change parts of strings, we use index values or subscripts. These are numbers that tell us the position of each character.

🎯 Exam Tip: Both 'index value' and 'subscript' refer to the numerical position of characters in a string, and both are fundamental for accessing and manipulating specific parts of the string.

 

Question 7. The negative subscript is always begun with
(a) 0
(b) -1
(c) 1
(d) -1.0
Answer: (b) -1
In simple words: When counting from the end of a string in Python, the very last character is given the index -1. This helps to access elements easily from the reverse direction.

🎯 Exam Tip: Remember that positive indices start from 0 at the beginning of the string, while negative indices start from -1 at the end.

 

Question 8. Which of the following operators are useful to do string manipulation?
(a) +, -
(b) %, *
(c) + *
(d) ; "
Answer: (c) + *
In simple words: The plus sign (+) is used to join strings together (concatenation), and the asterisk (*) is used to repeat a string multiple times. These are basic tools for changing strings.

🎯 Exam Tip: Always recall the basic uses of '+' for combining strings and '*' for repeating them, as these are fundamental in string operations.

 

Question 9. Adding more strings at the end of existing strings is ..........
(a) Append
(b) Concatenation
(c) Repetition
(d) Slicing
Answer: (a) Append
In simple words: When you add extra characters or another string to the very end of an existing string, it is called appending. It simply means adding something to the end.

🎯 Exam Tip: While concatenation combines strings, "appending" specifically refers to adding to the end, often using the `+=` operator for convenience.

 

Question 10. Python provides a function to change all occurrences of a particular character in a string.
(a) replace()
(b) change ()
(c) change all ()
(d) repalce all ()
Answer: (a) replace()
In simple words: The `replace()` function in Python lets you find all instances of a specific character or group of characters in a string and change them to something else. This function creates a new string with the changes.

🎯 Exam Tip: Remember that `replace()` returns a new string and does not change the original string because strings are immutable in Python.

 

Question 11. The operator is used to append a new string with an existing string.
(a) +
(b) +=
(c) *=
(d) ++
Answer: (b) +=
In simple words: The `+=` operator is a shortcut to add a new string to the end of an existing string and then save the new longer string back into the same variable. For example, `str1 += str2` is the same as `str1 = str1 + str2`.

🎯 Exam Tip: Understand that `+=` is a compound assignment operator, combining addition (concatenation for strings) and assignment in one step.

 

Question 12. The operator is used to display a string multiple times.
(a) *
(b) **
(c) *=
(d) + +
Answer: (a) *
In simple words: The asterisk (*) operator is used to repeat a string a certain number of times. If you write ` "hello" * 3 `, it will give you `"hellohellohello"`.

🎯 Exam Tip: Know that the repetition operator `*` always takes an integer as the second operand to specify how many times the string should be repeated.

 

Question 13. Escape sequences starts with a
(a) /
(b) \
(c) //
(d) \"
Answer: (b) \
In simple words: Escape sequences are special characters in Python, like `\n` for a new line or `\t` for a tab, and they always begin with a backslash `\`. This tells Python to treat the next character specially.

🎯 Exam Tip: Recognize the backslash `\` as the key indicator for an escape sequence, used to represent characters that are otherwise difficult to type or have special meaning.

 

Question 14. In python, the end value is considered as ..........
(a) 0
(b) n
(c) n - 1
(d) 1
Answer: (c) n - 1
In simple words: When you specify a range in Python (like in slicing), the end value you provide is not included in the result. Python goes up to, but does not include, that final position. So, if your string has 'n' characters, the index for the last character is 'n-1'.

🎯 Exam Tip: Always remember Python's "exclusive end" principle for ranges and slices, meaning the element at the `end` index is excluded from the result.

 

Question 15. The .......... function is a powerful function used for formatting strings.
(a) format ()
(b) string ()
(c) Slice ()
(d) format string ()
Answer: (a) format ()
In simple words: The `format()` function helps you create strings with custom details, like putting values into specific spots within a sentence. It makes strings easier to read and understand by replacing placeholders.

🎯 Exam Tip: Practice using `format()` with curly braces `{}` as placeholders for dynamic string creation, especially when combining text with variables.

 

Question 16. Formatting operator which is used to represent signed decimal integer.
(a) %d or %i
(b) %s or %c
(c) %g or %x
(d) %s or %e
Answer: (a) %d or %i
In simple words: When you want to show a whole number that can be positive or negative (signed decimal integer) in a formatted string, you use `%d` or `%i`. These tell Python how to display the number correctly.

🎯 Exam Tip: Familiarize yourself with common string formatting operators, as `%d` and `%i` are essential for displaying integers, while others handle different data types.

 

Question 1. Write the general format of slice operation.
Answer: The general way to write a slice operation in Python is `str[start:end]`. Here, `start` is the position where the slice begins, and `end` is the position where it stops. Python considers the `start` index but stops *before* including the `end` index. This means the end value is effectively `n-1` characters. For example, to get the first 4 characters, you would use `[0:4]`, which includes characters at indices 0, 1, 2, and 3.
In simple words: Slicing uses `[start:end]` to pick a part of a string. It starts at `start` and goes up to, but not including, `end`.

🎯 Exam Tip: Clearly state the `str[start:end]` syntax and explain both `start` (inclusive) and `end` (exclusive) parameters to show full understanding.

 

Question 2. What is meant by stride?
Answer: Stride is a third optional argument used in string slicing operations. It tells Python how many characters to skip forward after retrieving each character from the string. The normal, or default, value for stride is 1, meaning it moves one character at a time. A slice itself is a smaller part, or substring, of a larger string.
In simple words: Stride is a step size in slicing, telling Python to jump characters. If you don't set it, the step size is 1.

🎯 Exam Tip: Explain stride as the "step value" in slicing (`str[start:end:stride]`) and mention its default value of 1 for comprehensive understanding.

 

Question 3. Write a note on Append Operator?
Answer: The append operator, written as `+=`, is used to add new strings to the end of an existing string. This operation is effectively a shortcut for concatenating a string with itself and then assigning the result back to the original string variable. For instance, if `str1 = "Hello"` and you want to add "World" to it, you can simply write `str1 += "World"`, and `str1` will become "HelloWorld". This is a clean way to extend strings in Python.
In simple words: The `+=` operator lets you add text to the end of a string quickly. It saves the new, longer string back into the same variable.

🎯 Exam Tip: Provide an example using `str1 += "new_string"` to illustrate the practical application of the append operator and its convenience.

 

Question 4. What is the use of find () function? Explain with an example.
Answer: The `find()` function in Python is used to locate the first appearance of a specific smaller string (substring) within a larger string. If the substring is found, the function returns the starting position (index) of that first occurrence. If the substring is not found, it returns `-1`. You can also tell `find()` to search only within a certain part of the string by giving `start` and `end` positions. It is important to remember that this search is sensitive to uppercase and lowercase letters.
Function: find ()
Syntax: `find(sub[,start[, end]])`
Description:
β€’ The function searches for the first time a substring appears in the given string.
β€’ It returns the index where the substring begins.
β€’ If the substring is not found, it returns -1.
β€’ The `start` and `end` arguments are optional, allowing you to define a specific range for the search. Without them, it searches the whole string.
β€’ The search is case-sensitive.
Example:
`>>> str1='mammals'`
`>>> str1.find('ma')`
`0`
(This means 'ma' starts at index 0 in 'mammals'.)
`>>> str1.find('ma',2)`
`3`
(This means 'ma' starts at index 3 when searching from index 2.)
`>>> str1.find('ma',2,4)`
`-1`
(This returns -1 because 'ma' is not found between index 2 and index 3 (4-1=3)).
In simple words: The `find()` function looks for a small piece of text inside a bigger text. It tells you where it starts or if it is not there at all.

🎯 Exam Tip: Crucially mention that `find()` returns the starting index if found, and `-1` if not, and that the search is case-sensitive. Provide a simple example.

 

Question 5. Write a note on lower () and islower () functions.
Answer:
**`lower()` Function**
Description: The `lower()` function creates and returns a brand new string where all the characters of the original string are converted to their lowercase form. The original string remains unchanged.
Syntax: `str.lower()`
Example:
`>>> str1='SAVE EARTH'`
`>>> print(str1.lower())`
`save earth`

**`islower()` Function**
Description: The `islower()` function checks if all the characters in a string are lowercase. It returns `True` if every character is lowercase (and there's at least one letter). If even one character is uppercase, or if the string is empty or contains no letters, it returns `False`.
Syntax: `str.islower()`
Example:
`>>> str1='welcome'`
`>>> print(str1.islower())`
`True`
`>>> str1='Welcome'`
`>>> print(str1.islower())`
`False`
In simple words: `lower()` makes all letters in a string small, giving you a new string. `islower()` checks if all letters in a string are already small and tells you `True` or `False`.

🎯 Exam Tip: Distinguish clearly that `lower()` *transforms* a string, while `islower()` *tests* a string and returns a boolean (`True`/`False`) value.

 

Question 6. Differentiate upper () and isupper ().
Answer:

Function: `upper()`Function: `isupper()`
Syntax: `str.upper()`Syntax: `str.isupper()`
Description: Returns a new string where all letters are converted to uppercase.Description: Returns `True` if all letters in the string are uppercase, otherwise returns `False`.
Example:
`>>> str1='welcome'`
`>>> print(str1.upper())`
`WELCOME`
Example:
`>>> str1='WELCOME'`
`>>> print(str1.isupper())`
`True`
`>>> str1='Welcome'`
`>>> print(str1.isupper())`
`False`

In simple words: `upper()` changes all letters in a string to capital letters and gives you the new string. `isupper()` just checks if all letters in a string are already capital and tells you `True` or `False`.

🎯 Exam Tip: When differentiating, always highlight that functions like `upper()` *modify* (return a new modified string) while `isupper()` *test* a condition (return a boolean result).

 

Question 7. What will be the output of the given Python program?
Answer:
Code:
`str="COMPUTER SCIENCE"`
(a) `print(str*2)`
(b) `print(str[0: 7])`
Output:
`COMPUTER SCIENCE`
(i) `print(str*2)` will output `COMPUTER SCIENCECOMPUTER SCIENCE`
(ii) `print(str[0: 7])` will output `COMPUTER`
In simple words: When you multiply a string by a number, it repeats the string that many times. When you slice a string using `[0:7]`, it means you take characters from the start (index 0) up to, but not including, index 7.

🎯 Exam Tip: Pay close attention to string multiplication for repetition and string slicing, remembering that the `end` index in slicing is exclusive.

 

Question 8. Write notes on (a) isalnum (), (b) isalpha () and (c) isdigit ()
Answer:
**(a) `isalnum()` Function:**
Syntax: `str.isalnum()`
Description: This function checks if all characters in the string are alphanumeric. Alphanumeric means they are either letters (alphabetical) or numbers (digits). If the string contains any spaces or special characters like `*` or `#`, it returns `False`. Otherwise, it returns `True`. The string must also have at least one character.
Example 1:
`>>> str1='Save Earth'`
`>>> str1.isalnum()`
`False`
(Returns `False` because of the space character)
Example 2:
`>>> str1='save1Earth'`
`>>> str1.isalnum()`
`True`

**(b) `isalpha()` Function:**
Syntax: `str.isalpha()`
Description: This function checks if all characters in the string are alphabetical (letters only). If the string contains any numbers, spaces, or special characters, it returns `False`. Otherwise, it returns `True`. The string must also contain at least one letter.
Example 1:
`>>> str1='SaveiEarth'`
`>>> str1.isalpha()`
`False`
(Returns `False` because it contains digits)
Example 2:
`>>> str1='SaveEarth'`
`>>> str1.isalpha()`
`True`

**(c) `isdigit()` Function:**
Syntax: `str.isdigit()`
Description: This function checks if all characters in the string are digits (numbers only). If the string contains any letters, spaces, or special characters, it returns `False`. Otherwise, it returns `True`. The string must also contain at least one digit.
Example 1:
`>>> str1='Save1Earth'`
`>>> str1.isdigit()`
`False`
Example 2:
`>>> str1='12345'`
`>>> str1.isdigit()`
`True`
In simple words: `isalnum()` checks if text has only letters and numbers. `isalpha()` checks if text has only letters. `isdigit()` checks if text has only numbers. They all return `True` or `False`.

🎯 Exam Tip: For each function, clearly state its purpose (alphanumeric, alphabetic, digit only) and provide a concise example with its expected boolean output.

 

Question 9. Write notes on Formatting Characters
Answer: Formatting characters are special symbols used with string formatting methods (like the old style `%` operator or `format()` method) to control how different types of data are displayed within a string. They specify the data type (e.g., integer, string, float) and how it should be presented (e.g., decimal, hexadecimal, exponential). Using them helps to create neat and structured output.

Format CharactersUsage
%cCharacter
%d (or) %iSigned decimal integer
%sString
%uUnsigned decimal integer
%oOctal integer
%x or %XHexadecimal integer (lower case x refers a-f; upper case X refers A-F)
%e or %EExponential notation
%fFloating point numbers
%g or %GShort numbers in floating-point or exponential notation.

In simple words: Formatting characters are like codes that tell Python how to show numbers and text inside a string. They help make the output look tidy, like showing a number as a whole number or with decimals.

🎯 Exam Tip: Memorize the common formatting characters and their corresponding data types (e.g., `%d` for integer, `%s` for string, `%f` for float) as they are frequently tested.

 

Question 10. Give the general format of replace function.
Answer: The general format of the `replace()` function in Python is `string.replace("old_char", "new_char")`. This function is used to find all instances of a specified substring (`old_char`) within the string and replace them with another specified substring (`new_char`). It then returns a *new* string with all the replacements made. The original string remains unchanged because strings are immutable.
Example:
`>>> str1="How are you"`
`>>> print(str1)`
`How are you`
`>>> print(str1.replace("o", "e"))`
`Hew are yeu`
In simple words: The `replace()` function takes two pieces of text: what to find and what to put instead. It finds all old text and swaps it with new text, then gives you the updated string.

🎯 Exam Tip: Clearly state the syntax `string.replace(old, new)` and emphasize that it returns a *new* string with replacements, leaving the original string untouched.

 

Question 11. Write a note on Escape Sequence in Python
Answer: Escape sequences are special characters in Python strings that begin with a backslash `\`. They allow you to include characters that are otherwise difficult or impossible to type directly into a string, such as newlines, tabs, or quotation marks that would normally end the string. These sequences are interpreted specially by Python to represent certain actions or characters. For instance, `\n` creates a new line, and `\t` creates a tab space. They are essential for controlling the layout and content of string output.

Escape SequenceDescription
`\newline`Backslash and newline ignored (used for breaking long lines of code)
`\\`Backslash character itself
`\'`Single quote character
`\"`Double quote character
`\a`ASCII Bell (alerts with a sound)
`\b`ASCII Backspace
`\f`ASCII Form feed (new page character)
`\n`ASCII Linefeed (new line)
`\r`ASCII Carriage Return (moves cursor to the start of the current line)
`\t`ASCII Horizontal Tab
`\v`ASCII Vertical Tab
`\ooo`Character with octal value `ooo`
`\xHH`Character with hexadecimal value `HH`

In simple words: Escape sequences are special codes that start with `\` (backslash). They help you put characters like new lines or quotation marks into your text without confusing Python.

🎯 Exam Tip: Remember that all escape sequences begin with a backslash `\` and are used to represent special characters or actions within strings.

 

Question 12. What will be the output of the following Python code?
Answer:
Code:
`str1 = "Madurai"`
`print(str1*3)`
Output:
`MaduraiMaduraiMadurai`
In simple words: When a string is multiplied by a number, the string is simply repeated that many times right next to itself.

🎯 Exam Tip: String multiplication repeats the string; ensure there are no spaces or extra characters in the output unless they are part of the original string.

 

Question 13. What will be output of the following Python snippet?
Answer:
Code:
`print(str1[4::2])`
`print(str1[::3])`
`print(str1[::-3])`
Output (assuming `str1="THIRUKKURAL"` from previous context, otherwise the question is incomplete):
`>>> str1="THIRUKKURAL"`
`>>> print(str1[4::2])`
`KPRL`
`>>> print(str1[::3])`
`TIUL`
`>>> print(str1[::-3])`
`MIAO`
In simple words: Slicing `[start:end:step]` extracts parts of a string. `[4::2]` starts at index 4 and takes every second character. `[::3]` takes every third character from the beginning. `[::-3]` takes every third character, starting from the end and going backward.

🎯 Exam Tip: Master the three parts of string slicing (`start:end:step`) and understand how a negative step value reverses the string traversal.

 

Question 14. What will be the output of the following python program?
Answer:
Code:
`str1 = "welcome"`
`str2 = "to school"`
`str3 = str1[:3] + str2[len(str2)-1:]`
`print(str3)`
Output:
`welol`
Explanation:
1. `str1[:3]` means "wel" (characters from index 0 up to, but not including, index 3).
2. `len(str2)` is `9`.
3. `len(str2)-1` is `8`.
4. `str2[len(str2)-1:]` means `str2[8:]`, which takes characters from index 8 to the end. The character at index 8 in "to school" is 'l'.
5. `str3` becomes `"wel" + "ol"` which is `"welol"`.
In simple words: The code takes the first three letters of "welcome" (`wel`) and adds them to the last two letters of "to school" (`ol`). The `len(str2)-1:` finds the character at the second-to-last position until the end.

🎯 Exam Tip: Break down complex string operations step-by-step, evaluating each slice and concatenation individually to arrive at the correct final output.

 

Question 1. Write a python program to check whether the given string is palindrome or not.
Answer: A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. This program will take a string from the user and then reverse it to see if it matches the original. This is a good way to understand how to reverse strings and compare them.
Python Program:
`str1 = input ("Enter a string:")`
`str2 = ""`
`index = -1`
`for i in str1:`
    `str2 += str1 [index]`
    `index -= 1`
`print ("The given string = {} \n The Reversed string = {}".format(str1, str2))`
`if str1 == str2:`
    `print ("Hence, the given string is Palindrome")`
`else:`
    `print ("Hence, the given is not a palindrome")`
In simple words: This program takes text, reverses it, and then checks if the original text and the reversed text are exactly the same. If they match, it's a palindrome.

🎯 Exam Tip: The core logic for palindrome checking involves comparing the original string with its reversed version. Ensure your code handles both conditions for palindrome and non-palindrome correctly.

 

Question 2. Write a python program to display the number of vowels and consonants in the given string.
Answer: This program counts how many vowels (a, e, i, o, u) and consonants are present in a string entered by the user. It iterates through each character of the string, converting it to lowercase to simplify the check, and then increments the appropriate counter. This helps in understanding string iteration and conditional checks.
Python Program:
`str1 = input ("Enter a string:")`
`str2 = "aAeEiloOuU"` (This string contains all vowels, both lowercase and uppercase)
`v, c = 0, 0`
`for i in str1:`
    `if i in str2:`
        `v += 1`
    `else:`
        `c += 1`
`print ("The given string contains {} vowels and {} consonants.".format(v, c))`
In simple words: This program takes some text, then counts how many letters are vowels (a, e, i, o, u) and how many are other letters (consonants). It checks each letter one by one.

🎯 Exam Tip: Ensure your program handles both uppercase and lowercase letters for vowels by either converting the input string to a single case or including both cases in your vowel reference string.

 

Question 3. Explain how the positive and negative subscript values are assigned? Give example.
Answer: In Python, strings are ordered sequences, and each character has a specific position called an index or subscript. These indices can be positive or negative. Positive subscripts start from the beginning of the string, with `0` for the first character, `1` for the second, and so on, up to `n-1` for the last character, where `n` is the total length of the string. Negative subscripts, on the other hand, start from the end of the string, with `-1` representing the last character, `-2` for the second to last, and so forth, back to `-n` for the first character. This dual indexing system allows flexible access to characters from either direction.
Example: For the string "PYTHON":

CharacterPYTHON
Positive subscript012345
Negative subscript-6-5-4-3-2-1

In simple words: Positive numbers count characters from the start (0, 1, 2...). Negative numbers count characters from the end (-1, -2, -3...). Both ways help find any character in a string.

🎯 Exam Tip: Clearly define both positive (starting from 0, ending at `n-1`) and negative (starting from -1, ending at `-n`) indexing, and illustrate with a simple example string.

 

Question 5. Write the output for the following Python commands: str1="Welcome to Python"
(i) print(str1)
(ii) print(str1[11: 17])
(iii) print(str1[11: 17 : 2])
(v) print(str1[:: -4])
Answer:
(i) Welcome to Python
(ii) Python
(iii) Pto
(v) nytoW
In simple words: The commands perform different string operations. The first prints the whole string. The second prints a slice from index 11 to 16. The third prints a slice with a step of 2. The last prints the string in reverse, stepping back by 4 characters each time.

🎯 Exam Tip: Pay close attention to slice notation, especially the start, end, and stride values. Remember that the end index in Python slicing is exclusive.

 

Question 6. Write a program to accept a string and print it in reverse order.
Answer:
Coding:
str1 = input ("Enter a string:")
index = -1
while index >= -(len(str1)):
print ("Subscript", index, "] :", str1[index])
index += -1
Output:
Enter a string: welcome Subscript [ -1 ]: e
Subscript [ -2 ]: m
Subscript [ -4 ]: c
Subscript [-5]: l
Subscript [-6]: e
Subscript [ -7 ] :w
In simple words: This program takes a word from the user and then prints each letter of the word one by one, starting from the last letter and moving backward. It also shows the negative index for each letter.

🎯 Exam Tip: When writing programs to manipulate strings, remember that Python uses zero-based indexing for positive numbers (from left) and -1 for the last character (from right). Negative indexing is very useful for reverse operations.

 

Question 7. Write a simple python program with list of five marks and print the sum of all the marks using while loop.
Answer:
Python Program:
mark = []
for x in range(0,5):
num = int(input("Enter Mark:"))
mark += (num,)
print(mark)
c = len(mark)
i = 0
sum = 0
while i < c:
sum += mark[i]
i += 1
print("Sum=", sum)
Output:
Enter Mark:60
Enter Mark:70
Enter Mark:80
Enter Mark:90
Enter Mark:100
[60, 70, 80, 90, 100]
Sum= 400
In simple words: This program first asks the user to enter five marks. It stores these marks in a list. Then, it uses a `while` loop to go through each mark in the list and add them all up. Finally, it prints the total sum of all the marks.

🎯 Exam Tip: Always initialize your sum variable to zero before starting a loop to accumulate values, otherwise you might get unexpected results. Ensure the loop condition correctly covers all elements in the list.

TN Board Solutions Class 12 Computer Science Chapter 08 Strings and String Manipulations

Students can now access the TN Board Solutions for Chapter 08 Strings and String Manipulations prepared by teachers on our website. These solutions cover all questions in exercise in your Class 12 Computer Science textbook. Each answer is updated based on the current academic session as per the latest TN Board syllabus.

Detailed Explanations for Chapter 08 Strings and String Manipulations

Our expert teachers have provided step-by-step explanations for all the difficult questions in the Class 12 Computer Science chapter. Along with the final answers, we have also explained the concept behind it to help you build stronger understanding of each topic. This will be really helpful for Class 12 students who want to understand both theoretical and practical questions. By studying these TN Board Questions and Answers your basic concepts will improve a lot.

Benefits of using Computer Science Class 12 Solved Papers

Using our Computer Science solutions regularly students will be able to improve their logical thinking and problem-solving speed. These Class 12 solutions are a guide for self-study and homework assistance. Along with the chapter-wise solutions, you should also refer to our Revision Notes and Sample Papers for Chapter 08 Strings and String Manipulations to get a complete preparation experience.

FAQs

Where can I find the latest Samacheer Kalvi Class 12 Computer Science Solutions Chapter 8 Strings and String Manipulations for the 2026-27 session?

The complete and updated Samacheer Kalvi Class 12 Computer Science Solutions Chapter 8 Strings and String Manipulations is available for free on StudiesToday.com. These solutions for Class 12 Computer Science are as per latest TN Board curriculum.

Are the Computer Science TN Board solutions for Class 12 updated for the new 50% competency-based exam pattern?

Yes, our experts have revised the Samacheer Kalvi Class 12 Computer Science Solutions Chapter 8 Strings and String Manipulations as per 2026 exam pattern. All textbook exercises have been solved and have added explanation about how the Computer Science concepts are applied in case-study and assertion-reasoning questions.

How do these Class 12 TN Board solutions help in scoring 90% plus marks?

Toppers recommend using TN Board language because TN Board marking schemes are strictly based on textbook definitions. Our Samacheer Kalvi Class 12 Computer Science Solutions Chapter 8 Strings and String Manipulations will help students to get full marks in the theory paper.

Do you offer Samacheer Kalvi Class 12 Computer Science Solutions Chapter 8 Strings and String Manipulations in multiple languages like Hindi and English?

Yes, we provide bilingual support for Class 12 Computer Science. You can access Samacheer Kalvi Class 12 Computer Science Solutions Chapter 8 Strings and String Manipulations in both English and Hindi medium.

Is it possible to download the Computer Science TN Board solutions for Class 12 as a PDF?

Yes, you can download the entire Samacheer Kalvi Class 12 Computer Science Solutions Chapter 8 Strings and String Manipulations in printable PDF format for offline study on any device.