ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print(str.maketrans('ab', 'xy', 'c'), 'abcabc'.translate(str.maketrans('ab', 'xy', 'c')))- A. {97: 120, 98: 121, 99: None} xyxy
- B. {97: 120, 98: 121, 99: 99} xyxy
- C. {97: 120, 98: 121, 99: None} xyc
- D. {97: 'x', 98: 'y', 99: None} xyxy
Correct answer: A. {97: 120, 98: 121, 99: None} xyxy
maketrans maps code points: a (97) to x (120), b (98) to y (121), and the third argument's character c (99) to None, which deletes it. So 'abcabc' becomes 'xyxy'.
More Python Programming questions
- What is printed? python print(sorted(['10', '9', '100', '2']), sorted(map(int, ['10', '9', '100', '2'])))
- What is printed? python print(-7 // -2, 7 // -2 -2 + 7 % -2)
- What is printed? python print(round(-2.5), round(-3.5), round(7, -1), round(15, -1), round(25, -1))
- What is printed? python print(int('12abc', 36), int('zz', 36), int('-z', 36))
- What is printed? python print(hash(-1) == hash(-2), hash(-1), hash(261 - 1))
- What is printed? python print(int.bitlength(-255), (255).bitlength(), (256).bitlength())