A directory of Objective Type Questions covering all the Computer Science subjects. Here you can access and discuss Multiple choice questions and answers for various compitative exams and interviews.

Important Notice!

Dear users, compscibits.com is now permanently moved to compsciedu.com. Please update all your links and bookmarks accordingly. Soon, the site will be accessible through URL compsciedu.com only.

31. What is “Hello”.replace(“l”, “e”)
a. Heeeo
b. Heelo
c. Heleo
d. None
View Answer Report Discuss Too Difficult! Search Google
Answer: (a).Heeeo

32. To retrieve the character at index 3 from string s=”Hello” , what command do we execute ?
a. s[].
b. s.getitem(3)
c. s.__getitem__(3)
d. s.getItem(3)
View Answer Report Discuss Too Difficult! Search Google
Answer: (c).s.__getitem__(3)

33. To return the length of string s what command do we execute ?
a. s.__len__()
b. len(s)
c. size(s)
d. s.size()
View Answer Report Discuss Too Difficult! Search Google
Answer: (a).s.__len__()

34. 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
View Answer Report Discuss Too Difficult! Search Google
Answer: (d).All of the mentioned

35. 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)
View Answer Report Discuss Too Difficult! Search Google
Answer: (a).s1.__contains__(s2)

36. 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)
View Answer Report Discuss Too Difficult! Search Google
Answer: (b).i.__add__(j)

37. 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))
a. True False
b. True True
c. False True
d. False False
View Answer Report Discuss Too Difficult! Search Google
Answer: (c).False True

38. 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)
a. Peter Pan
b. John Pan
c. Peter Smith
d. John Smith
View Answer Report Discuss Too Difficult! Search Google
Answer: (b).John Pan

39. 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”))
View Answer Report Discuss Too Difficult! Search Google
Answer: (a).input(“Enter a string”)

40. 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
View Answer Report Discuss Too Difficult! Search Google
Answer: (b).___345.355

Page 4 of 13