π€ Computational Thinking & Programming-I Quiz 10 β Strings in Python (Class 11 CS)
Practice 20 CBSE Class 11 Computer Science (Code 083) MCQs on strings β string operations (concatenation, repetition, membership, slicing), traversing a string with loops, and essential built-in string methods like len(), capitalize(), title(), count(), find(), index(), split(), join(), partition(), and replace().
Every function behaviour below has been verified by actually running it in Python. Tap any question to reveal the answer with a clear explanation.
π€ String Basics
What is a string in programming?
- A sequence of numbers
- A sequence of characters
- A mathematical equation
- A geometric shape
Show Answer & Explanation
β Answer: (b) A sequence of characters
A string is a sequence of characters β letters, digits, symbols, or spaces β enclosed in quotes, like "Hello".
β String Operations
Which of the following string operations combines two or more strings together?
- Concatenation
- Repetition
- Membership
- Slicing
Show Answer & Explanation
β Answer: (a) Concatenation
Concatenation (using the + operator) joins two or more strings end to end into a single new string, e.g. "Hello" + " World".
β String Operations
Which of the following string operations repeats a string a certain number of times?
- Concatenation
- Repetition
- Membership
- Slicing
Show Answer & Explanation
β Answer: (b) Repetition
Repetition (using the * operator) repeats a string multiple times, e.g. "ab" * 3 gives "ababab".
β String Operations
What does the membership operation do with strings?
- Checks if a string is contained in another string
- Splits a string into multiple substrings
- Reverses the order of characters in a string
- Extracts a portion of a string
Show Answer & Explanation
β Answer: (a) Checks if a string is contained in another string
The membership operators (in and not in) check whether one string appears somewhere inside another string.
β String Operations
How can you traverse a string in Python, visiting each character one at a time?
- Using a for loop
- Using the print() function alone
- Using an f-string
- Using the type() function
Show Answer & Explanation
β Answer: (a) Using a for loop
A for loop (e.g. for ch in my_string:) is the standard way to traverse a string, visiting each character in order β a while loop with an index can also work, but the for loop is the cleanest and most common approach.
π§° Built-in Functions
Which built-in function is used to determine the length of a string?
- len()
- count()
- find()
- replace()
Show Answer & Explanation
β Answer: (a) len()
len() returns the number of characters in a string, e.g. len("Hello") gives 5.
π§° Built-in Functions
Which built-in function is used to capitalize just the first character of a string?
- len()
- capitalize()
- count()
- find()
Show Answer & Explanation
β Answer: (b) capitalize()
capitalize() makes only the very first character uppercase and lowercases the rest of the string.
π§° Built-in Functions
Which built-in function converts the first character of EVERY word in a string to uppercase?
- title()
- lower()
- upper()
- replace()
Show Answer & Explanation
β Answer: (a) title()
title() capitalizes the first letter of each word in the string, turning βhello worldβ into βHello Worldβ.
π§° Built-in Functions
Which built-in function is used to convert an entire string to lowercase?
- len()
- capitalize()
- lower()
- upper()
Show Answer & Explanation
β Answer: (c) lower()
lower() converts every uppercase letter in the string to lowercase, leaving everything else unchanged.
π§° Built-in Functions
Which built-in function is used to count the occurrences of a substring within a string?
- len()
- capitalize()
- count()
- find()
Show Answer & Explanation
β Answer: (c) count()
count() tallies how many times a given substring appears in the string, e.g. "hello".count("l") gives 2.
π§° Built-in Functions
Which built-in function is used to find the index of the FIRST occurrence of a substring, raising an error if it isn’t found?
- count()
- find()
- index()
- replace()
Show Answer & Explanation
β Answer: (c) index()
index() behaves like find() but raises a ValueError if the substring isn’t present, instead of quietly returning -1.
π§° Built-in Functions
Which built-in function is used to check if a string ends with a specific substring?
- endswith()
- startswith()
- isalnum()
- isspace()
Show Answer & Explanation
β Answer: (a) endswith()
endswith() returns True or False depending on whether the string finishes with the given substring.
π§° Built-in Functions
Which built-in function is used to check if a string starts with a specific substring?
- endswith()
- startswith()
- isalnum()
- isspace()
Show Answer & Explanation
β Answer: (b) startswith()
startswith() returns True or False depending on whether the string begins with the given substring.
π§° Built-in Functions
Which built-in function checks whether a string contains ONLY letters and/or digits (no spaces or symbols)?
- isalnum()
- isalpha()
- isdigit()
- isspace()
Show Answer & Explanation
β Answer: (a) isalnum()
isalnum() returns True only if every character in the string is either a letter or a digit.
π§° Built-in Functions
Which built-in function is used to remove whitespace from only the LEFT side of a string?
- lstrip()
- rstrip()
- strip()
- join()
Show Answer & Explanation
β Answer: (a) lstrip()
lstrip() removes leading whitespace (from the left/start only). rstrip() does the right side only, and strip() does both ends.
β String Operations
Which string operation is used to extract a portion of a string using a start:stop:step pattern?
- Concatenation
- Repetition
- Slicing
- Membership
Show Answer & Explanation
β Answer: (c) Slicing
Slicing (e.g. s[0:5]) extracts a substring by specifying a start index, a stop index, and an optional step β "Hello World"[0:5] gives "Hello".
π§° Built-in Functions
Which method splits a string into a list of substrings based on a separator (whitespace by default)?
- split()
- join()
- partition()
- replace()
Show Answer & Explanation
β Answer: (a) split()
split() breaks a string apart wherever the separator occurs and returns a list, e.g. "Hello World".split() gives ['Hello', 'World'].
π§° Built-in Functions
Which method combines the elements of a list into a single string, using a given separator between them?
- split()
- join()
- partition()
- strip()
Show Answer & Explanation
β Answer: (b) join()
join() is called on the separator string and takes a list as its argument: "-".join(["a","b","c"]) gives "a-b-c".
π§° Built-in Functions
Which method splits a string into a 3-part tuple β the part before the separator, the separator itself, and the part after β based on its FIRST occurrence?
- split()
- join()
- partition()
- replace()
Show Answer & Explanation
β Answer: (c) partition()
partition() splits around the first occurrence of a separator and always returns exactly 3 pieces: "key=value".partition("=") gives ('key', '=', 'value').
π§° Built-in Functions
Which method replaces every occurrence of one substring with another substring?
- find()
- count()
- replace()
- index()
Show Answer & Explanation
β Answer: (c) replace()
replace(old, new) substitutes every matching occurrence of old with new throughout the string: "Hello World".replace("World", "Python") gives "Hello Python".
