ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
L = list(range(10)) L[2:8:2] = "XYZ" del L[-3:] L[len(L):] = [99] print(L)
- A. [0, 1, 'X', 3, 'Y', 5, 'Z', 7, 99]
- B. [0, 1, 'XYZ', 3, 5, 7, 99]
- C. [0, 1, 'X', 'Y', 'Z', 5, 99]
- D. [0, 1, 'X', 3, 'Y', 5, 'Z', 99]
Correct answer: D. [0, 1, 'X', 3, 'Y', 5, 'Z', 99]
The extended slice selects indices 2, 4, 6, which receive X, Y, Z. Deleting the last three removes 7, 8, 9. Assigning to the empty slice at the end appends.
More Python Programming questions
- What is printed? python d = {"b": 2, "a": 1} print(sorted(d.items()), sorted(d, key=d.get), list(reversed(sorted(d.values()))), {d, "a"…
- What is printed? python from collections import Counter c = Counter(a=3, b=1) c.update("aab") c.subtract({"b": 5}) print(c["a"], c["b"]…
- What is printed? python from collections import ChainMap defaults = {"color": "red", "size": 1} user = {"size": 3} cm = ChainMap(user…
- What is printed? python import bisect grades = "FDCBA" cut = [60, 70, 80, 90] print([grades[bisect.bisect(cut, s)] for s in [59, 60, 85…
- What is printed? python x = [1, 2, 3] y = [x, x] y[0] = y[0] + [4] y[1] += [5] print(x, y)
- What is printed? python def f(a, b=[]): b = b + [a] f.defaults = (b,) return b print(f(1), f(2), f(3, []), f(4))