ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
s = "abcdefghij" print(s[2:8:3], s[-2:-9:-3], s[8:2:3] == "", s[::4] + s[1::4])
- A. cf ifc True aeibf
- B. cfi ifc True aeibfj
- C. cf ifc True aeibfj
- D. cf if True aeibfj
Correct answer: C. cf ifc True aeibfj
s[2:8:3] takes indices 2 and 5 ('c', 'f'). s[-2:-9:-3] starts at index 8 and takes 8, 5, 2 ('i', 'f', 'c'). A positive step with start > stop is empty. s[::4] is 'aei' and s[1::4] is 'bfj'.
More Python Programming questions
- What is printed? python L = list(range(10)) L[2:8:2] = "XYZ" del L[-3:] L[len(L):] = [99] print(L)
- 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)