Python Programming (2180711) MCQs

MCQs of Structured Types, Mutability and Higher-Order Functions

Showing 31 to 40 out of 48 Questions
31.
Which of the following statements is used to create an empty set?
(a) { }
(b) set()
(c) [ ]
(d) ( )
Answer:

Option (b)

32.
If a={5,6,7,8}, which of the following statements is false?
(a) print(len(a))
(b) print(min(a))
(c) a.remove(5)
(d) a[2]=45
Answer:

Option (d)

33.
If a={5,6,7}, what happens when a.add(5) is executed?
(a) a={5,5,6,7}
(b) a={5,6,7}
(c) Error as there is no add function for set data type
(d) Error as 5 already exists in the set
Answer:

Option (b)

34.
What will be the output of the following Python code?
>>> a={5,6,7,8}
>>> b={7,5,6,8}
>>> a==b
(a) TRUE
(b) FALSE
Answer:

Option (a)

35.
Which of the following statements create a dictionary?
(a) d = {}
(b) d = {“john”:40, “peter”:45}
(c) d = {40:”john”, 45:”peter”}
(d) All of the mentioned
Answer:

Option (d)

36.
Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use?
(a) d.delete(“john”:40)
(b) d.delete(“john”)
(c) del d[“john”]
(d) del d(“john”:40)
Answer:

Option (c)

37.
Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in a dictionary which command do we use?
(a) d.size()
(b) len(d)
(c) size(d)
(d) d.len()
Answer:

Option (b)

38.
Suppose d = {“john”:40, “peter”:45}, what happens when we try to retrieve a value using the expression d[“susan”]?
(a) Since “susan” is not a value in the set, Python raises a KeyError exception
(b) It is executed fine and no exception is raised, and it returns None
(c) Since “susan” is not a key in the set, Python raises a KeyError exception
(d) Since “susan” is not a key in the set, Python raises a syntax error
Answer:

Option (c)

39.
Which of these about a dictionary is false?
(a) The values of a dictionary can be accessed using keys
(b) The keys of a dictionary can be accessed using values
(c) Dictionaries aren’t ordered
(d) Dictionaries are mutable
Answer:

Option (b)

40.
Which of the following is not a declaration of the dictionary?
(a) {1: ‘A’, 2: ‘B’}
(b) dict([[1,”A”],[2,”B”]])
(c) {1,”A”,2”B”}
(d) { }
Answer:

Option (c)

Showing 31 to 40 out of 48 Questions