ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
s = 'abc' print(s * 0 == '', s[::-1][::-1] == s, s[1:-1] * 2, s[-3:-1])
- A. True True b ab
- B. True False bb ab
- C. True True bb a
- D. True True bb ab
Correct answer: D. True True bb ab
s[1:-1] is 'b', and repeating it twice gives 'bb'. Reversing a string twice returns the original, and s[-3:-1] takes the first two characters, 'ab'.
More Python Programming questions
- What is printed? python print(sorted(['x10', 'x9', 'x1'], key=lambda s: int(s[1:])))
- What is printed? python print(0.1 3 == 0.3, 0.1 3 == 3 0.1, round(0.1 3, 1) == 0.3, 1 - 0.9 == 0.1)
- What is printed? python print('%s' % [1, 'a'], '%r' % 'a', '%5.2s|' % 'hello', '%c' % 65)
- What is printed? python print(hash(1.5) == hash(3/2), hash(True) == hash(1), {0: 'x', False: 'y'}, len({1: 'a', True: 'b', 1.0: 'c'}))
- What is printed? python print(min(3, 2.0, True), max(1, 1.0), max(1.0, 1))
- What is printed? python print(253 == float(253), 253 + 1 == float(253 + 1), 253 + 2 == float(253 + 2))