Skip to content
TestMacher
Chapter 9 · Class 11 Computer Science

Strings — Important Questions

59 questions With answers CBSE format

SUMMARY: This chapter focuses on the concept of strings in Python, including their properties and manipulation techniques.
KEY TOPICS: string definition, string indexing, string slicing, string methods, string concatenation, string immutability, escape sequences, string formatting, string comparison, string operations

Q1 1 Mark

Which method is used to convert a string to uppercase in Python?

Aupper()
Buppercase()
CtoUpper()
Dup()
Check answerHide answer
Correct answer: Option 1 — upper()
Q2 1 Mark

The output of "Hello"[1:4] is:

AHel
Bell
Cello
DHello
Check answerHide answer
Correct answer: Option 2 — ell
Q3 1 Mark

Which method is used to find the length of a string?

Alength()
Blen()
Csize()
Dcount()
Check answerHide answer
Correct answer: Option 2 — len()
Q4 1 Mark

The output of "abc" * 3 is:

Aabcabcabc
Babc3
Cabc abc abc
DError
Check answerHide answer
Correct answer: Option 1 — abcabcabc
Q5 1 Mark

Strings in Python are:

AMutable
BImmutable
CBoth
DNeither
Check answerHide answer
Correct answer: Option 2 — Immutable
Q6 1 Mark

What is the result of the expression 'Python' + 'Programming'?

APythonProgramming
BPython Programming
CPython-Programming
DPython+Programming
Check answerHide answer
Correct answer: Option 2 — Python Programming
Q7 1 Mark

Which of the following escape sequences represents a newline in a string?

A\t
B\n
C\r
D\b
Check answerHide answer
Correct answer: Option 2 — \n
Q8 1 Mark

What will be the output of 'Hello, World!'[7:]?

AHello,
BWorld!
CHello
DHello, World!
Check answerHide answer
Correct answer: Option 2 — World!
Q9 1 Mark

Which method would you use to replace 'cat' with 'dog' in the string 'The cat is here'?

Areplace('cat', 'dog')
Bchange('cat', 'dog')
Cswap('cat', 'dog')
Dupdate('cat', 'dog')
Check answerHide answer
Correct answer: Option 1 — replace('cat', 'dog')
Q10 1 Mark

What is the output of 'abc'[::-1]?

Aabc
Bcba
Cbac
Dab
Check answerHide answer
Correct answer: Option 2 — cba
Q11 1 Mark

Which of the following statements about strings in Python is true?

AStrings are mutable.
BStrings can be concatenated using the + operator.
CStrings do not support indexing.
DStrings can only contain letters.
Check answerHide answer
Correct answer: Option 2 — Strings can be concatenated using the + operator.
Q12 1 Mark

What will be the result of 'A' < 'B'?

ATrue
BFalse
CNone
DError
Check answerHide answer
Correct answer: Option 1 — True
Q13 1 Mark

Which of the following methods can be used to convert the first character of a string to uppercase?

Acapitalize()
Bupper()
Ctitle()
Dfirst_upper()
Check answerHide answer
Correct answer: Option 1 — capitalize()
Q14 1 Mark

What does the method 'strip()' do when applied to a string?

ARemoves all characters from the string.
BRemoves leading and trailing whitespace.
CRemoves vowels from the string.
DRemoves punctuation from the string.
Check answerHide answer
Correct answer: Option 2 — Removes leading and trailing whitespace.
Q15 1 Mark

In Python, which of the following is a valid way to format a string?

A'Hello, {}'.format(name)
B'Hello, %s' % name
Cf'Hello, {name}'
DAll of the above
Check answerHide answer
Correct answer: Option 4 — All of the above
Q16 3 Marks

Differentiate between strip() lstrip() and rstrip() string methods.

Q17 3 Marks

Write Python code to count the number of vowels in a string.

Q18 3 Marks

Explain the use of split() and join() string methods with one example each.

Q19 3 Marks

What is string slicing? Give one example.

Q20 3 Marks

Differentiate between find() and index() string methods.

Q21 3 Marks

What is string immutability in Python? Provide an example to illustrate your answer.

View sample solutionHide solution
String immutability means that once a string is created in Python, it cannot be changed or modified. For example, if we have a string s = 'Hello', trying to change it to s[0] = 'h' will result in a TypeError.
Q22 3 Marks

Explain how string concatenation works in Python. Provide a code example.

View sample solutionHide solution
String concatenation in Python is the process of joining two or more strings together using the '+' operator. For example, if we have s1 = 'Hello' and s2 = 'World', then s1 + ' ' + s2 will result in 'Hello World'.
Q23 3 Marks

What are escape sequences in Python strings? Give two examples.

View sample solutionHide solution
Escape sequences are special character combinations that allow us to include characters in a string that are otherwise difficult to type. For example, '\n' represents a new line and '\t' represents a tab space.
Q24 3 Marks

Describe the purpose of the format() method in Python strings. Provide an example.

View sample solutionHide solution
The format() method in Python strings is used for string formatting, allowing us to insert variables into a string. For example, 'Hello, {}'.format('World') will output 'Hello, World'.
Q25 3 Marks

What is string indexing? How would you access the first character of a string in Python?

View sample solutionHide solution
String indexing refers to accessing individual characters in a string using their position, starting from 0. For example, for the string s = 'Python', s[0] will give 'P', the first character.
Q26 6 Marks

Differentiate between list and string in Python in tabular form.

Q27 6 Marks

Compare find() and index() string methods with the help of a table.

Q28 6 Marks

Differentiate between strip() lstrip() and rstrip() in tabular form.

Q29 6 Marks

Write a Python program to check if a given string is a palindrome ignoring case.

Q30 6 Marks

Discuss any five built-in string methods with one example each.

Q31 6 Marks

Write a Python program to count the frequency of each character in a string.

Q32 1 Mark

Assertion (A): Strings are immutable in Python.

Reason (R): Once created their characters cannot be changed in place.

Show explanationHide explanation
Correct answer: Option 1 — Both A and R are true, and R is the correct explanation of A.
Q33 1 Mark

Assertion (A): Negative indexing in strings starts from the end.

Reason (R): The last character has index -1.

Show explanationHide explanation
Correct answer: Option 1 — Both A and R are true, and R is the correct explanation of A.
Q34 1 Mark

Assertion (A): The * operator can be used to repeat a string.

Reason (R): It is overloaded for sequences in Python.

Show explanationHide explanation
Correct answer: Option 1 — Both A and R are true, and R is the correct explanation of A.
Q35 1 Mark

Assertion (A): Strings can be enclosed in single double or triple quotes.

Reason (R): Triple quotes allow multi-line strings.

Show explanationHide explanation
Correct answer: Option 1 — Both A and R are true, and R is the correct explanation of A.
Q36 1 Mark

Assertion (A): The 'in' operator checks substring membership.

Reason (R): It returns True if the substring is found.

Show explanationHide explanation
Correct answer: Option 1 — Both A and R are true, and R is the correct explanation of A.
Q37 1 Mark

Assertion (A): String slicing can be used to extract a substring from a string.

Reason (R): String slicing uses the syntax string[start:end] to obtain a portion of the string.

Show explanationHide explanation
Correct answer: Option 1 — Both A and R are true, and R is the correct explanation of A.
Q38 1 Mark

Assertion (A): The method str.upper() converts all characters in a string to lowercase.

Reason (R): The str.upper() method is designed to convert all characters in a string to uppercase.

Show explanationHide explanation
Correct answer: Option 3 — A is true, but R is false.
Q39 1 Mark

Assertion (A): Escape sequences in strings are used to represent special characters.

Reason (R): Escape sequences begin with a backslash and allow for the inclusion of characters that are otherwise difficult to represent.

Show explanationHide explanation
Correct answer: Option 1 — Both A and R are true, and R is the correct explanation of A.
Q40 1 Mark

Statement 1: Strings can be sliced using the [start:stop:step] syntax.

Statement 2: Negative indices count from the end.

Show answerHide answer
Correct answer: Option 1 — Both statements are true.
Q41 1 Mark

Statement 1: String concatenation is done using the + operator.

Statement 2: String repetition uses the * operator.

Show answerHide answer
Correct answer: Option 1 — Both statements are true.
Q42 1 Mark

Statement 1: len() returns the length of a string.

Statement 2: It works on any sequence type.

Show answerHide answer
Correct answer: Option 1 — Both statements are true.
Q43 1 Mark

Statement 1: The split() method breaks a string into a list.

Statement 2: The join() method joins list items into a string.

Show answerHide answer
Correct answer: Option 1 — Both statements are true.
Q44 1 Mark

Statement 1: Escape sequences begin with a backslash.

Statement 2: Examples include \\n for newline and \\t for tab.

Show answerHide answer
Correct answer: Option 1 — Both statements are true.
Q45 1 Mark

Statement 1: String indexing in Python starts from 1.

Statement 2: The first character of a string can be accessed using index 0.

Show answerHide answer
Correct answer: Option 2 — Only Statement 1 is true.
Q46 1 Mark

Statement 1: Strings in Python are mutable, allowing modification of individual characters.

Statement 2: The string 'hello' can be formatted using f-strings in Python.

Show answerHide answer
Correct answer: Option 3 — Only Statement 2 is true.
Q47 1 Mark

Statement 1: The method upper() converts all characters in a string to lowercase.

Statement 2: The method lower() converts all characters in a string to uppercase.

Show answerHide answer
Correct answer: Option 4 — Both statements are false.
Q48 3 Marks
A student is asked to write a Python program to count the number of vowels in a given string. She decides to use a for loop to iterate over each character and a counter variable to keep track of the vowel count. She also wants to handle both uppercase and lowercase vowels.
  1. Which Python function returns the length of a string?
    Alen
    Blength
    Ccount
    Dsize
  2. Strings in Python are:
    AMutable
    BImmutable
    COrdered list
    DRandom list
  3. Write the complete Python program to count vowels and explain how it handles uppercase letters.
Show answersHide answers
1. Option 1 — len
2. Option 2 — Immutable
3. The Python program is: s = input('Enter string: ').lower(); count = 0; for ch in s: if ch in 'aeiou': count += 1; print('Number of vowels:' count). The lower() method ensures both uppercase and lowercase vowels are counted. The 'in' operator tests membership in the vowel list. We initialise count = 0 then iterate over each character.
Q49 3 Marks
In Python, a string is a sequence of characters enclosed within single quotes, double quotes, or triple quotes. Strings are immutable, meaning that once a string is created, it cannot be modified. For example, if we have a string 'Hello', we cannot change it to 'Hello World' directly; instead, we would create a new string. Strings can be indexed, allowing access to individual characters using their position. The first character has an index of 0, the second character an index of 1, and so on. Additionally, Python supports string slicing, which enables us to extract a substring from a string by specifying a start and end index. For instance, 'Hello'[1:4] would return 'ell'.
  1. What does it mean that strings are immutable in Python?
  2. What will be the output of the expression 'Hello'[1:4]?
    AHello
    Bell
    CHe
    Dlo
  3. What is the index of the first character in a string?
    A1
    B0
    C2
    D-1
Show answersHide answers
1. Strings cannot be changed after they are created.
2. Option 2 — ell
3. Option 2 — 0
Q50 3 Marks
String concatenation in Python is the process of joining two or more strings together using the '+' operator. For example, if we have two strings, 'Hello' and 'World', we can concatenate them as 'Hello' + ' ' + 'World', which results in 'Hello World'. Additionally, Python provides various string methods that allow for manipulation and formatting of strings. For instance, the method .upper() converts all characters in a string to uppercase, while .lower() converts them to lowercase. These methods do not change the original string but return a new string with the desired modifications.
  1. What is the result of concatenating 'Hello' and 'World' with a space in between?
    AHelloWorld
    BHello World
    CHello_World
    DHello+World
  2. Explain the purpose of the .upper() method in Python strings.
  3. Does the .lower() method modify the original string?
    AYes
    BNo
    COnly if it is a variable
    DIt depends on the string length
Show answersHide answers
1. Option 2 — Hello World
2. .upper() converts all characters in a string to uppercase.
3. Option 2 — No
Q51 3 Marks
String comparison in Python allows you to check if two strings are equal or if one string is greater than another based on lexicographical order. This means that strings are compared character by character based on their ASCII values. For example, the string 'apple' is less than 'banana' because the ASCII value of 'a' is less than 'b'. Python uses the '==' operator to check for equality and the '<' or '>' operators to compare strings. It is important to note that string comparison is case-sensitive, so 'Apple' and 'apple' are considered different.
  1. How does Python determine the order of strings during comparison?
    ABy length of the strings
    BBy ASCII values of characters
    CBy the first character only
    DBy the last character only
  2. What will be the result of comparing 'Apple' and 'apple'?
    AEqual
    BNot equal
    CGreater than
    DLess than
  3. What operator is used to check for equality between two strings?
Show answersHide answers
1. Option 2 — By ASCII values of characters
2. Option 2 — Not equal
3. '==' operator is used for equality check.
Q52 6 Marks

Predict the output of each string operation.

s = 'Hello World'Result
len(s)?
s.upper()?
s[0:5]?
s[-1]?
s.split()?
'World' in s?
Q53 3 Marks

Study the table of common string methods and answer:

MethodUseExample output
upper()Uppercase'hello'.upper() = HELLO
lower()Lowercase'Hello'.lower() = hello
strip()Remove whitespace' ab '.strip() = ab
split()Split into list'a b c'.split() = ['a','b','c']
replace()Replace substring'cat'.replace('c','b') = bat
  1. Which method converts a string to uppercase?
    Aupper()
    Buppercase()
    CtoUpper()
    Dup()
  2. Which method splits a string into a list?
    Ajoin
    Bsplit
    Cbreak
    Ddivide
  3. Discuss any five string methods with one example each.
Show answersHide answers
1. Option 1 — upper()
2. Option 2 — split
3. Strings in Python are immutable so each method returns a new string instead of modifying the original. Common operations include case conversion (upper lower title) whitespace handling (strip lstrip rstrip) splitting/joining (split join) searching (find index in) and replacing (replace). The split() method takes an optional separator (default whitespace).
Q54 6 Marks

What is the length of the string 'Python Programming' as shown in the table?

StringLength
Python Programming18
Java Programming16
Q55 2 Marks

Study the following data and answer the questions below:

StringUppercaseLowercase
helloHELLOhello
WORLDWORLDworld
PythonPYTHONpython
  1. What is the uppercase form of the string 'hello'?
  2. Which string has the same uppercase and lowercase representation?
Show answersHide answers
1.
2.
Q56 3 Marks

Study the string indexing diagram and answer:

Strings figure
  1. For s = 'PYTHON' what is s[-1]?
    AP
    BY
    CN
    DO
  2. For s = 'PYTHON' what is s[0:3]?
    APYT
    BPYTH
    CYTH
    DONHT
  3. Explain string indexing and slicing with examples.
Show answersHide answers
1. Option 3 — N
2. Option 1 — PYT
3. Python strings support both positive (0 1 2 ...) and negative (-1 -2 ...) indexing. Slicing uses [start:stop:step] where stop is exclusive. s[0:3] gives the first 3 characters. s[-3:] gives the last 3. s[::-1] reverses the string. Strings are immutable so slicing returns new strings.
Q57 2 Marks

Based on the given diagram of string slicing in Python, answer the following:

Strings figure
  1. What does the slice 'string[1:4]' return?
    Astr
    Btri
    Cing
    Ding
  2. Explain the output of 'string[:3]'.
Show answersHide answers
1. Option 3 — ing
2. The output will be the first three characters of the string.
Q58 2 Marks

Based on the given flowchart of string methods in Python, answer the following:

Strings figure
  1. Which method would you use to convert a string to lowercase?
    AUppercase
    BLowercase
    CStrip
    DReplace
  2. What does the 'strip' method do?
Show answersHide answers
1. Option 2 — Lowercase
2. The 'strip' method removes any leading and trailing whitespace from the string.
Q59 2 Marks

Based on the given diagram showing string concatenation, answer the following:

Strings figure
  1. What is the result of concatenating 'Hello' and 'World'?
    AHelloWorld
    BHello World
    CHello+World
    DHello, World!
  2. Describe how string concatenation is performed in Python.
Show answersHide answers
1. Option 2 — Hello World
2. String concatenation is performed using the '+' operator to combine two or more strings.

Make a full Computer Science paper on Strings.

Pick the question mix, set the marks, hit generate. You get a ready-to-print paper with an answer key.

Generate your paper — free