Objective Questions and Answers: Strings
Explore reliable objective questions for Strings tailored for learners. Utilizing these multiple-choice formats ensures thorough preparation and strengthens problem-solving speed for upcoming school assessments.
Download Strings MCQs with Answers
Navigate directly to the 50 objective questions for Strings using the digital viewer below. Each practice set includes verified answer keys, allowing students to instantly cross-check their work and identify areas requiring further revision.
Question. What is “Hello”.replace(“l”, “e”)?
(a) Heeeo
(b) Heelo
(c) Heleo
(d) None
Answer: a
Explanation: Execute in shell to verify.
Question. To retrieve the character at index 3 from string s=”Hello” what command do we execute (multiple answers allowed)?
(a) s[]
(b) s.getitem(3)
(c) \(s.\_\_getitem\_\_(3)\)
(d) s.getItem(3)
Answer: c
Explanation: __getitem(..) can be used to get character at index specified as parameter.
Question. To return the length of string s what command do we execute?
(a) \(s.\_\_len\_\_()\)
(b) len(s)
(c) size(s)
(d) s.size()
Answer: a
Explanation: Execute in shell to verify.
Question. If a class defines the \( \_\_str\_\_(self) \) method, for an object obj for the class, you can use which command to invoke the \( \_\_str\_\_ \) method.
(a) \(obj.\_\_str\_\_()\)
(b) str(obj)
(c) print obj
(d) all of the mentioned
Answer: d
Explanation: Execute in shell to verify.
Question. To check whether string s1 contains another string s2, use ________
(a) \(s1.\_\_contains\_\_(s2)\)
(b) s2 in s1
(c) s1.contains(s2)
(d) si.in(s2)
Answer: a
Explanation: s2 in s1 works in the same way as calling the special function \( \_\_contains\_\_ \).
Question. Suppose i is 5 and j is 4, i + j is same as ________
(a) \(i.\_\_add(j)\)
(b) \(i.\_\_add\_\_(j)\)
(c) \(i.\_\_Add(j)\)
(d) \(i.\_\_ADD(j)\)
Answer: b
Explanation: Execute in shell to verify.
Question. What will be the output of the following Python code?
class Count:
def __init__(self, count = 0):
self.__count = count
c1 = Count(2)
c2 = Count(2)
print(id(c1) == id(c2), end = " ")
s1 = "Good"
s2 = "Good"
print(id(s1) == id(s2))
(a) True False
(b) True True
(c) False True
(d) False False
Answer: c
Explanation: Execute in the shell objects cannot have same id, however in the case of strings its different.
Question. What will be the output of the following Python code?
class Name:
def __init__(self, firstName, mi, lastName):
self.firstName = firstName
self.mi = mi
self.lastName = lastName
firstName = "John"
name = Name(firstName, 'F', "Smith")
firstName = "Peter"
name.lastName = "Pan"
print(name.firstName, name.lastName)
(a) Peter Pan
(b) John Pan
(c) Peter Smith
(d) John Smith
Answer: b
Explanation: Execute in the shell to verify.
Question. What function do you use to read a string?
(a) input(“Enter a string”)
(b) eval(input(“Enter a string”))
(c) enter(“Enter a string”)
(d) eval(enter(“Enter a string”))
Answer: a
Explanation: Execute in shell to verify.
Question. Suppose x is 345.3546, what is format(x, “10.3f”) (_ indicates space).
(a) __345.355
(b) ___345.355
(c) ____345.355
(d) _____345.354
Answer: b
Explanation: Execute in the shell to verify.
Question. What will be the output of the following Python code?
print("abc DEF".capitalize())
(a) abc def
(b) ABC DEF
(c) Abc def
(d) Abc Def
Answer: c
Explanation: The first letter of the string is converted to uppercase and the others are converted to lowercase.
Question. What will be the output of the following Python code?
print("abc. DEF".capitalize())
(a) abc. def
(b) ABC. DEF
(c) Abc. def
(d) Abc. Def
Answer: c
Explanation: The first letter of the string is converted to uppercase and the others are converted to lowercase.
Question. What will be the output of the following Python code?
print("abcdef".center())
(a) cd
(b) abcdef
(c) error
(d) none of the mentioned
Answer: c
Explanation: The function center() takes at least one parameter.
Question. What will be the output of the following Python code?
print("abcdef".center(0))
(a) cd
(b) abcdef
(c) error
(d) none of the mentioned
Answer: b
Explanation: The entire string is printed when the argument passed to center() is less than the length of the string.
Question. What will be the output of the following Python code?
print('*', "abcdef".center(7), '*')
(a) * abcdef *
(b) * abcdef *
(c) *abcdef *
(d) * abcdef*
Answer: b
Explanation: Padding is done towards the left-hand-side first when the final string is of odd length. Extra spaces are present since we haven’t overridden the value of sep.
Question. What will be the output of the following Python code?
print('*', "abcdef".center(7), '*', sep='')
(a) * abcdef *
(b) * abcdef *
(c) *abcdef *
(d) * abcdef*
Answer: d
Explanation: Padding is done towards the left-hand-side first when the final string is of odd length.
Question. What will be the output of the following Python code?
print('*', "abcde".center(6), '*', sep='')
(a) * abcde *
(b) * abcde *
(c) *abcde *
(d) * abcde*
Answer: c
Explanation: Padding is done towards the right-hand-side first when the final string is of even length.
Question. What will be the output of the following Python code?
print("abcdef".center(7, 1))
(a) 1abcdef
(b) abcdef1
(c) abcdef
(d) error
Answer: d
Explanation: TypeError, the fill character must be a character, not an int.
Question. What will be the output of the following Python code?
print("abcdef".center(7, '1'))
(a) 1abcdef
(b) abcdef1
(c) abcdef
(d) error
Answer: a
Explanation: The character ‘1’ is used for padding instead of a space.
Question. What will be the output of the following Python code?
print("abcdef".center(10, '12'))
(a) 12abcdef12
(b) abcdef1212
(c) 1212abcdef
(d) error
Answer: d
Explanation: The fill character must be exactly one character long.
Question. What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('yy'))
(a) 2
(b) 0
(c) error
(d) none of the mentioned
Answer: a
Explanation: Counts the number of times the substring ‘yy’ is present in the given string.
Question. What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('yy', 1))
(a) 2
(b) 0
(c) 1
(d) none of the mentioned
Answer: a
Explanation: Counts the number of times the substring ‘yy’ is present in the given string, starting from position 1.
Question. What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('yy', 2))
(a) 2
(b) 0
(c) 1
(d) none of the mentioned
Answer: c
Explanation: Counts the number of times the substring ‘yy’ is present in the given string, starting from position 2.
Question. What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('xyy', 0, 100))
(a) 2
(b) 0
(c) 1
(d) error
Answer: a
Explanation: An error will not occur if the end value is greater than the length of the string itself.
Question. What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('xyy', 2, 11))
(a) 2
(b) 0
(c) 1
(d) error
Answer: b
Explanation: Counts the number of times the substring ‘xyy’ is present in the given string, starting from position 2 and ending at position 11.
Question. What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('xyy', -10, -1))
(a) 2
(b) 0
(c) 1
(d) error
Answer: b
Explanation: Counts the number of times the substring ‘xyy’ is present in the given string, starting from position 2 and ending at position 11.
Question. What will be the output of the following Python code?
print('abc'.encode())
(a) abc
(b) ‘abc’
(c) b’abc’
(d) h’abc’
Answer: c
Explanation: A bytes object is returned by encode.
Question. What is the default value of encoding in encode()?
(a) ascii
(b) qwerty
(c) utf-8
(d) utf-16
Answer: c
Explanation: The default value of encoding is utf-8.
Question. What will be the output of the following Python code?
print("xyyzxyzxzxyy".endswith("xyy"))
(a) 1
(b) True
(c) 3
(d) 2
Answer: b
Explanation: The function returns True if the given string ends with the specified substring.
Question. What will be the output of the following Python code?
print("xyyzxyzxzxyy".endswith("xyy", 0, 2))
(a) 0
(b) 1
(c) True
(d) False
Answer: d
Explanation: The function returns False if the given string does not end with the specified substring.
Multiple Choice Questions (MCQs) for Strings
Strings Objective Test Questions
Test your conceptual understanding of Strings with these targeted multiple-choice questions. Designed in alignment with the latest NCERT curriculum for , these problem sets build accuracy and prepare students for objective exams.
NCERT-Aligned Objective Questions and Solutions
Cross-reference your completed choices with comprehensive NCERT solutions for to ensure absolute clarity across all sub-topics in this chapter.
Next Steps in Your Exam Preparation
Wrap up your chapter revision by testing your knowledge against standard question formats. Everything on our platform is provided free of charge.
FAQs
You can get most exhaustive Python Strings MCQs with Answers Set 02 for free on StudiesToday.com. These MCQs for are updated for the 2026-27 academic session as per examination standards.
Yes, our Python Strings MCQs with Answers Set 02 include the latest type of questions, such as Assertion-Reasoning and Case-based MCQs. 50% of the paper is now competency-based.
By solving our Python Strings MCQs with Answers Set 02, students can improve their accuracy and speed which is important as objective questions provide a chance to secure 100% marks in the .
Yes, MCQs for have answer key and brief explanations to help students understand logic behind the correct option as its important for 2026 competency-focused exams.
Yes, you can also access online interactive tests for Python Strings MCQs with Answers Set 02 on StudiesToday.com as they provide instant answers and score to help you track your progress in .