ProgrammingVery hardGATE CS · Product-company placement
What is printed?
What is printed?
s = "abc" print(repr(s[1:1] + s[3:] + s[-1:-2]), s[0:0] == s[5:9], len(s[-5:5]), s[True:])
- A. 'c' True 3 bc
- B. '' False 3 bc
- C. '' True 3 bc
- D. '' True 3 TypeError
Correct answer: C. '' True 3 bc
All three slices are empty (s[-1:-2] runs forward from index 2 to 1). Out-of-range bounds are clipped, so s[5:9] is '' and s[-5:5] is the whole string. True is an int equal to 1, so s[True:] is 'bc'.
More Python Programming questions
- What is printed? python w = ["bob", "Al", "al", "Bo"] print(sorted(w), sorted(w, key=str.lower))
- What is printed? python people = [("ann", 30), ("bob", 25), ("cid", 30), ("dan", 25)] people.sort(key=lambda p: p[0], reverse=True)…
- What is printed? python nums = [4, -1, 3, -1, 2] print(sorted(nums, key=lambda v: (v < 0, -v)), sorted(set(nums), reverse=True)[:2])
- What is printed? python def walk(d, depth=0): out = [] for k, v in d.items(): out.append(f"{k}{depth}") if isinstance(v, dict): out +=…
- What is printed? python def hanoi(n): return 0 if n == 0 else 2 hanoi(n - 1) + 1 def calls(n): return 1 if n == 0 else 1 + 2 calls(n - 1)…
- What is printed? python import sys def depth(n): try: return depth(n + 1) except RecursionError: return n d = depth(0) print(d > 500, d <…