Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.

Unit 2 MCQs Python data structures

ECAP776 60 questions. Pick an option to check it.

Read the notes Subjective questions

0 of 60 answered 0 right 0 wrong , 60 left

  1. Question 1 of 60 Strings Easy

    Which Python data structure represents a sequence of characters?

  2. Question 2 of 60 Strings Easy

    What is the result of "Python"[0]?

  3. Question 3 of 60 Strings Easy

    Which string method converts all letters to uppercase?

  4. Question 4 of 60 Strings Easy

    Which statement about Python strings is correct?

  5. Question 5 of 60 Lists Easy

    Which expression creates a Python list?

  6. Question 6 of 60 Lists Easy

    Which method adds one element to the end of a list?

  7. Question 7 of 60 Lists Easy

    What is the result of len([10, 20, 30])?

  8. Question 8 of 60 Lists Easy

    Which statement about Python lists is correct?

  9. Question 9 of 60 Sets Easy

    What is a main characteristic of a Python set?

  10. Question 10 of 60 Sets Easy

    Which expression creates a non-empty set?

  11. Question 11 of 60 Sets Easy

    Which method adds an element to a set?

  12. Question 12 of 60 Sets Easy

    What is the result of len({1, 1, 2, 3})?

  13. Question 13 of 60 Tuples Easy

    Which expression creates a tuple containing three values?

  14. Question 14 of 60 Tuples Easy

    Which statement about tuples is correct?

  15. Question 15 of 60 Tuples Easy

    Which expression creates a tuple containing only the value 5?

  16. Question 16 of 60 Tuples Easy

    What is the result of (10, 20, 30)[1]?

  17. Question 17 of 60 Dictionaries Easy

    What does a Python dictionary store?

  18. Question 18 of 60 Dictionaries Easy

    Which expression creates a dictionary?

  19. Question 19 of 60 Dictionaries Easy

    Given student = {"name": "Sam", "age": 18}, which expression returns "Sam"?

  20. Question 20 of 60 Dictionaries Easy

    Which dictionary method returns a view of all keys?

  21. Question 21 of 60 Strings Medium

    What is the value of result after this code?

    text = 'DataStructures'

    result = text[1:10:2]

  22. Question 22 of 60 Strings Medium

    What does the following expression return?

    'banana'.replace('a', 'o', 2)

  23. Question 23 of 60 Strings Medium

    What is printed by the following code?

    text = ' py thon '

    print(text.strip().replace(' ', '_'))

  24. Question 24 of 60 Strings Medium

    Given code = 'AB12-CD34', which expression returns '1234'?

  25. Question 25 of 60 Lists Medium

    What is printed by the following code?

    a = [[1, 2], [3, 4]]

    b = a.copy()

    b[0].append(5)

    b.append([6])

    print(a)

  26. Question 26 of 60 Lists Medium

    What is the value of result after this code?

    result = [x * 2 for x in range(6) if x % 2 != 0]

  27. Question 27 of 60 Lists Medium

    What is the final value of nums?

    nums = [0, 1, 2, 3, 4]

    nums[1:4] = [8, 9]

  28. Question 28 of 60 Lists Medium

    What does the following expression return?

    sorted(['pear', 'fig', 'apple', 'kiwi'], key=lambda x: (len(x), x))

  29. Question 29 of 60 Sets Medium

    What is the value of (A | B) - (A & B) when A = {1, 2, 3, 4} and B = {3, 4, 5}?

  30. Question 30 of 60 Sets Medium

    What is the value of the following set comprehension?

    {x % 3 for x in range(7)}

  31. Question 31 of 60 Sets Medium

    What is printed by the following code?

    s = {1, 2}

    s.discard(3)

    s.remove(2)

    print(s)

  32. Question 32 of 60 Sets Medium

    Given A = {1, 2} and B = {1, 2, 3}, which pair of expressions both evaluates to True?

  33. Question 33 of 60 Tuples Medium

    What are the values of a, b, and rest after this assignment?

    a, b, *rest = (1, 2, 3, 4)

  34. Question 34 of 60 Tuples Medium

    What is printed by the following code?

    t = ([1, 2], 'x')

    t[0].append(3)

    print(t)

  35. Question 35 of 60 Tuples Medium

    What does the following expression return?

    sorted([(2, 'b'), (1, 'c'), (1, 'a')])

  36. Question 36 of 60 Tuples Medium

    What is printed by the following code?

    t = (1, 2)

    u = t

    t += (3,)

    print(t, u)

  37. Question 37 of 60 Dictionaries Medium

    What is the value of d after this dictionary comprehension?

    d = {x % 2: x for x in range(5)}

  38. Question 38 of 60 Dictionaries Medium

    What is the final value of d?

    d = {'a': [1]}

    d.setdefault('a', []).append(2)

    d.setdefault('b', []).append(3)

  39. Question 39 of 60 Dictionaries Medium

    What is the value of merged after this code?

    d1 = {'a': 1, 'b': 2}

    d2 = {'b': 5, 'c': 6}

    merged = d1 | d2

  40. Question 40 of 60 Dictionaries Medium

    What is printed by the following code?

    original = {'x': [1]}

    clone = original.copy()

    clone['x'].append(2)

    print(original, clone)

  41. Question 41 of 60 Strings Hard

    What is the value of (s[8:1:-3], s[-2::-3], s[8:1:-3] == s[-2::-3]) when s = "0123456789"?

  42. Question 42 of 60 Strings Hard

    What does "mississippi".replace("iss", "X", 1).partition("s") return?

  43. Question 43 of 60 Strings Hard

    What string is produced by "{0[1]:0{1}d}".format([3, 7], 4)?

  44. Question 44 of 60 Strings Hard

    Given table = str.maketrans({"a": "xy", "b": None}), what is "abca".translate(table)?

  45. Question 45 of 60 Lists Hard

    What is a after executing a = [[0] * 2] * 3; a[0][1] = 7; a[1] = a[1] + [8]?

  46. Question 46 of 60 Lists Hard

    What is a after a = [0, 1, 2, 3, 4, 5]; a[1:5:2] = [9, 8]; a[2:4] = [7]?

  47. Question 47 of 60 Lists Hard

    What is the final value of a after a = [1, 2, 3, 4, 5, 6] followed by for x in a: a.remove(x) if x % 2 else None?

  48. Question 48 of 60 Lists Hard

    Given rows = [("a", 2), ("b", 1), ("c", 2), ("d", 1)], what is rows after rows.sort(key=lambda x: x[1]); rows.sort(key=lambda x: x[0] in {"b", "c"})?

  49. Question 49 of 60 Sets Hard

    For A = {1, 2, 3}, B = {2, 3, 4}, C = {3, 4, 5}, and D = {4}, what is A | B & C - D?

  50. Question 50 of 60 Sets Hard

    What is the value of (len(s), s == {0, 1, 2}) after s = {True, 1, 1.0, False, 0, 0.0, 2}?

  51. Question 51 of 60 Sets Hard

    For A = {1, 2}, B = {1, 2}, and C = frozenset({1, 2}), what is (A <= B, A < B, C == A)?

  52. Question 52 of 60 Sets Hard

    What does {1, 2} in {frozenset({1, 2}), frozenset()} evaluate to in Python?

  53. Question 53 of 60 Tuples Hard

    What are u and t after t = ([1],); u = t; t[0].append(2); t += ([3],)?

  54. Question 54 of 60 Tuples Hard

    After executing t = ([1, 2], [3]); try: t[0] += [4]\nexcept TypeError: pass, what is t?

  55. Question 55 of 60 Tuples Hard

    What is (a, b, c, d) after a, *b, (c, *d) = (1, 2, 3, (4, 5, 6))?

  56. Question 56 of 60 Tuples Hard

    Which tuple can be used as a dictionary key without raising TypeError?

  57. Question 57 of 60 Dictionaries Hard

    What is (len(d), list(d.keys()), d[True]) after d = {1: "int", True: "bool", 1.0: "float"}?

  58. Question 58 of 60 Dictionaries Hard

    What is d after d = dict.fromkeys(["a", "b"], []); d["a"].append(1); d["b"] = d["b"] + [2]?

  59. Question 59 of 60 Dictionaries Hard

    Given calls = [], def make(): calls.append("x"); return 99, and d = {"k": 1}, what are (v, calls, d) after v = d.setdefault("k", make())?

  60. Question 60 of 60 Dictionaries Hard

    What is list(d.items()) after d1 = {"a": 1, "b": 2}; d2 = {"b": 9, "c": 3, "a": 7}; d = d1 | d2?

That's unit 2

Answer a few questions and your score shows up here.