240). 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)

Show Answer

242). 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

Show Answer

243). 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)

Show Answer

245). 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

Show Answer

246). 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

Show Answer

247). What function do you use to read a string?
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]input(“Enter a string”)
[B]eval(input(“Enter a string”))
[C]enter(“Enter a string”)
[D]eval(enter(“Enter a string”))

Show Answer

248). Suppose x is 345.3546, what is format(x, “10.3f”) (_ indicates space).
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]__345.355
[B]___345.355
[C]____345.355
[D]_____345.354

Show Answer