gs gs109 Python Strings - Python Strings - Quiz No.4
gs gs109 Python Quiz
This quiz belongs to book/course code gs gs109 Python of gs organization. We have 134 quizzes available related to the book/course Python. This quiz has a total of 10 multiple choice questions (MCQs) to prepare and belongs to topic Python Strings. NVAEducation wants its users to help them learn in an easy way. For that purpose, you are free to prepare online MCQs and quizzes.
NVAEducation also facilitates users to contribute in online competitions with other students to make a challenging situation to learn in a creative way. You can create one to one, and group competition on an topic of a book/course code. Also on NVAEducation you can get certifications by passing the online quiz test.
Question 1: What is “Hello”.replace(“l”, “e”)?
Heeeo
Heelo
Heleo
None
Question 2: To retrieve the character at index 3 from string s=”Hello” what command do we execute (multiple answers allowed)?
s[]
s.getitem(3)
s.__getitem__(3)
s.getItem(3)
Question 3: To return the length of string s what command do we execute?
len(s) OR s.__len__()
len(s) only
size(s)
s.size()
Question 4: 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.
obj.__str__()
str(obj)
print obj
all of the mentioned
Question 5: To check whether string s1 contains another string s2, use ________
s1.__contains__(s2)
s2 in s1
s1.contains(s2)
si.in(s2)
Question 6: Suppose i is 5 and j is 4, i + j is same as ________
i.__add(j)
i.__add__(j)
i.__Add(j)
i.__ADD(j)
Question 8: 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)
Peter Pan
John Pan
Peter Smith
John Smith
Question 9: What function do you use to read a string?
input(“Enter a string”)
eval(input(“Enter a string”))
enter(“Enter a string”)
eval(enter(“Enter a string”))
Question 10: Suppose x is 345.3546, what is format(x, “10.3f”) (_ indicates space).
__345.355
___345.355
____345.355
_____345.354