ProgrammingHardProduct-company MCQ pattern
How many of the following statements about Python are correct? (i) A tuple that contains a list can be used as a dictionary key. (ii) A frozenset can be an element of a set. (iii) Strings support item assignment, e.g. s[0] = 'x'. (iv) list.sort() returns the sorted list.
- A. Only two
- B. Only one
- C. Only three
- D. All four
Correct answer: B. Only one
Only (ii) is true: a frozenset is immutable and hashable. (i) fails because hashing the tuple hashes the list inside it, which raises TypeError. (iii) strings are immutable. (iv) sort() returns None.
More Python Programming questions
- What is printed? python a = [1, 2, 3] a += [4] a = a + [5] a.extend("67") print(a)
- What is printed? python x = [[0] 3] 2 y = [[0] 3 for in range(2)] x[0][1] = 5 y[0][1] = 5 print(x, y)
- What is printed? python def add(item, bucket=[]): bucket.append(item) return bucket a = add(1) b = add(2) c = add(3, []) print(a, b, c, a…
- What is printed? python fs = [lambda: i i for i in range(4)] gs = [lambda i=i: i i for i in range(4)] print([f() for f in fs], [g() for g…
- What is printed? python s = "abcdefgh" print(s[1:6:2], s[::-3], s[-3:-1], len(s[5:2]))
- What is printed? python def gen(): for i in range(3): x = yield i print("got", x, end="; ") g = gen() print(next(g), end="; ")…