adplus-dvertising

Welcome to the Strings in Python MCQs Page

Dive deep into the fascinating world of Strings in Python with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Strings in Python, a crucial aspect of Python. In this section, you will encounter a diverse range of MCQs that cover various aspects of Strings in Python, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Python.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Strings in Python. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Python.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Strings in Python. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Strings in Python MCQs | Page 4 of 13

Q31.
What is “Hello”.replace(“l”, “e”)
Discuss
Answer: (a).Heeeo
Q32.
To retrieve the character at index 3 from string s=”Hello” , what command do we execute ?
Discuss
Answer: (c).s.__getitem__(3)
Q33.
To return the length of string s what command do we execute ?
Discuss
Answer: (a).s.__len__()
Q34.
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.
Discuss
Answer: (d).All of the mentioned
Q35.
To check whether string s1 contains another string s2, use
Discuss
Answer: (a).s1.__contains__(s2)
Q36.
Suppose i is 5 and j is 4, i + j is same as
Discuss
Answer: (b).i.__add__(j)
Q37.
What is the output of the following 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))
Discuss
Answer: (c).False True
Q38.
What is the output of the following 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)
Discuss
Answer: (b).John Pan
Discuss
Answer: (a).input(“Enter a string”)
Q40.
Suppose x is 345.3546, what is format(x, “10.3f”) (_ indicates space)
Discuss
Answer: (b).___345.355
Page 4 of 13

Suggested Topics

Are you eager to expand your knowledge beyond Python? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!