ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
t = str.maketrans('abc', 'xyz')
print('aabbcc'.translate(t), len(t))
  1. A. xxyyzz 3
  2. B. xxyyzz 6
  3. C. aabbcc 3
  4. D. xyzxyz 3

Correct answer: A. xxyyzz 3

maketrans builds a table that maps a to x, b to y and c to z. The table has three entries, one for each character mapped, and translate applies it character by character.

More Python Programming questions

Exams that ask this topic