ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
t = str.maketrans('abc', 'xyz')
print('aabbcc'.translate(t), len(t))- A. xxyyzz 3
- B. xxyyzz 6
- C. aabbcc 3
- 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
- What is printed? python import heapq h = [5, 1, 3, 1] heapq.heapify(h) print(h[0], heapq.heappop(h), heapq.nsmallest(2, [4, -1, 3])…
- What is printed? python from functools import reduce print(reduce(lambda a, b: a 10 + b, [1, 2, 3]), reduce(lambda a, b: a - b, [10, 2…
- What is printed? python print(sum(1 for c in 'a1b22c333' if c.isdigit()), ''.join(c for c in 'a1b22c333' if c.isalpha()), int(''.join(c…
- What is printed? python print(str(0.1 3), repr(0.1 3) == '0.30000000000000004', 0.1 3 == float(repr(0.1 3)))
- What is printed? python print(10-1 + 10-1 + 10-1 == 0.3, 1/10 + 1/10 + 1/10 == 0.3, 10-1 == 1/10)
- What is printed? python print(sorted([3, 1, 2], reverse=True) == [3, 2, 1], [3, 1, 2][::-1], sorted('cab')[::-1])