Python Programming (2180711) MCQs

MCQs of Structured Types, Mutability and Higher-Order Functions

Showing 41 to 48 out of 48 Questions
41.
What will be the output of the following Python code?
a={1:"A",2:"B",3:"C"}
for i,j in a.items():
    print(i,j,end=" ")
(a) 1 A 2 B 3 C
(b) 1 2 3
(c) A B C
(d) 1:”A” 2:”B” 3:”C”
Answer:

Option (a)

42.
Which of the following isn’t true about dictionary keys?
(a) More than one key isn’t allowed
(b) Keys must be immutable
(c) Keys must be integers
(d) When duplicate keys encountered, the last assignment wins
Answer:

Option (c)

43.
What will be the output of the following Python code?
>>> a={1:"A",2:"B",3:"C"}
>>> a.items()
(a) Syntax error
(b) dict_items([(‘A’), (‘B’), (‘C’)])
(c) dict_items([(1,2,3)])
(d) dict_items([(1, ‘A’), (2, ‘B’), (3, ‘C’)])
Answer:

Option (d)

44.
Which of the statements about dictionary values if false?
(a) More than one key can have the same value
(b) The values of the dictionary can be accessed as dict[key]
(c) Values of a dictionary must be unique
(d) Values of a dictionary can be a mixture of letters and numbers
Answer:

Option (c)

45.
If a is a dictionary with some key-value pairs, what does a.popitem() do?
(a) Removes an arbitrary element
(b) Removes all the key-value pairs
(c) Removes the key-value pair for the key given as an argument
(d) Invalid method for dictionary
Answer:

Option (a)

46.
If b is a dictionary, what does any(b) do?
(a) Returns True if any key of the dictionary is true
(b) Returns False if dictionary is empty
(c) Returns True if all keys of the dictionary are true
(d) Method any() doesn’t exist for dictionary
Answer:

Option (a)

47.
Which of the following functions is a built-in function in python?
(a) seed()
(b) sqrt()
(c) factorial()
(d) print()
Answer:

Option (d)

48.
Which of the following is the use of function in python?
(a) Functions are reusable pieces of programs
(b) Functions don’t provide better modularity for your application
(c) you can’t also create your own functions
(d) All of the mentioned
Answer:

Option (a)

Showing 41 to 48 out of 48 Questions