ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
s = 'hello' print(s[1:-1][::-1], s[-1:0:-2])
- A. lle lo
- B. ell ol
- C. lle oh
- D. lle ol
Correct answer: D. lle ol
s[1:-1] is 'ell', and reversing it gives 'lle'. s[-1:0:-2] takes index 4 and then index 2, which are o and l.
More Python Programming questions
- What is printed? python d = {} d.setdefault('k', []).append(1) d.setdefault('k', []).append(2) print(d)
- What is printed? python print(1 / 3 + 1 / 3 + 1 / 3 == 1.0, 0.1 + 0.7)
- What is printed? python print(sorted([(-1, 'b'), (-1, 'a'), (0, 'c')]), max([(1, 'z'), (1, 'a')]))
- What is printed? python x = 0 for i in range(5): x += i if i % 2 else -i print(x)
- What is printed? python it = iter([3, 1, 0, 5, 0]) out = [] for x in iter(lambda: next(it), 0): out.append(x) print(out, list(it))
- What is printed? python s = 'key=value=end' print(s.partition('='), s.rpartition('='), 'a b'.split(' '))