ProgrammingVery hardGATE CS · Product-company placement
What is printed?
What is printed?
s = "abcdef" print(s[5:1:-1], s[-1:-7:-1] == s[::-1], s[:-7:-1], s[2::-1])
- A. fedc True fedcba cba
- B. fedc False fedcba cba
- C. edcb True fedcba cba
- D. fedc True fedcb cb
Correct answer: A. fedc True fedcba cba
s[5:1:-1] takes indices 5 to 2: 'fedc'. -7 is before the start, so s[-1:-7:-1] and s[:-7:-1] both run to the beginning, equal to s[::-1]. s[2::-1] goes from index 2 back to 0: 'cba'.
More Python Programming questions
- What is printed? python d = {"a": 1, "b": 2, "c": 3} d["a"] = 10 del d["b"] d["b"] = 20 d.update({"a": 0, "z": 9}) print(list(d)…
- What is printed? python d = {0: "zero", False: "F", 0.0: "f", "": "e"} s = {1, True, 1.0, -0.0, 0} print(d, len(s))
- What is printed? python nan = float("nan") L = [nan] print(nan == nan, nan in L, L == [nan], [float("nan")] == [float("nan")])
- What is printed? python from collections import OrderedDict a = {"x": 1, "y": 2} b = {"y": 2, "x": 1} c = OrderedDict(a) e =…
- What is printed? python from collections import defaultdict d = defaultdict(list) d["a"].append(1) = d["b"] print("c" in d, d.get("c")…
- What is printed? python from collections import Counter a = Counter("aabbbc") b = Counter("abccd") print(sorted((a - b).items())…