ProgrammingModerateInfosys · Accenture · Capgemini pattern
What is printed?
What is printed?
s = "hello" print(s[::-2])
- A. oll
- B. hlo
- C. olh
- D. ol
Correct answer: C. olh
With step -2 the slice starts at the last index (4, 'o') and moves back two at a time: index 4 'o', index 2 'l', index 0 'h'.
More Python Programming questions
- What is printed? python t = (1,) print(type(t).name, type((1)).name)
- What is printed? python def f(args, kw): print(len(args), len(kw)) f(1, 2, a=3)
- What is printed? python print(list(zip([1, 2, 3], "ab")))
- What is printed? python print(" ".join(sorted(set("banana"))))
- What is printed? python try: print(1 / 0, end=" ") except ZeroDivisionError: print("Z", end=" ") finally: print("F")
- What is printed? python print(list(range(10, 0, -3)))