ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
s = "programming" print(s[-3:-8:-2], s[100:], s[-100:3])
- A. mmr pro
- B. imr pro
- C. rmi pro
- D. imr prog
Correct answer: B. imr pro
s[-3:-8:-2] starts at index 8 ('i') and takes indices 8, 6, 4 = 'i', 'm', 'r', stopping before index 3. Out-of-range slice bounds are clipped silently, so s[100:] is '' and s[-100:3] is 'pro'.
More Python Programming questions
- What is printed? python a = list(range(6)) try: a[::2] = [9, 9] except ValueError as e: print("VE", end=" ") a[1:2] = [] a[:0] = [7, 7]…
- What is printed? python a = [0, 1, 2, 3, 4, 5, 6, 7] del a[::3] print(a, a[-1:0:-2])
- What is printed? python s = slice(1, None, 2) t = "abcdefg" print(t[s], s.indices(len(t)), t[::-1][s])
- What is printed? python a = [1, 2, 3, 4, 5] a[1:4] = "xy" b = a[:] b[::-1] = b print(a, b[0])
- What is printed? python nums = [10, 20, 30, 40, 50] print(nums[-2::-2], nums[1:-1][::-1], nums[::-1][1:-1])
- What is printed? python s = "abcdef" print(s[5:1:-1], s[-1:-7:-1] == s[::-1], s[:-7:-1], s[2::-1])