Sail E0 Webinar

MCQs

Total Questions : 13 | Page 2 of 2 pages
Question 11. What is the output of the following?print('xyyxyyxyxyxxy'.replace('xy', '12', 100))
  1.    xyyxyyxyxyxxy
  2.    12y12y1212x12
  3.    none of the mentioned
  4.    error
 Discuss Question
Answer: Option B. -> 12y12y1212x12


The first 100 occurences of the given substring are replaced.


Question 12. What is the output of the following?print('a'.maketrans('ABC', '123'))
  1.    {97: 49, 98: 50, 99: 51}
  2.    {65: 49, 66: 50, 67: 51}
  3.    {97: 49}
  4.    1
 Discuss Question
Answer: Option A. -> {97: 49, 98: 50, 99: 51}


maketrans() is a static method so it's behaviour does not depend on the object from which it is being called.


Question 13. What is the output of the following?print('abcd'.translate({'a': '1', 'b': '2', 'c': '3', 'd': '4'}))
  1.    abcd
  2.    1234
  3.    error
  4.    none of the mentioned
 Discuss Question
Answer: Option A. -> abcd


The function translate expects a dictionary of integers. Use maketrans() instead of doing the above.


Latest Videos

Latest Test Papers