MCQOPTIONS
Saved Bookmarks
This section includes 1007 Mcqs, each offering curated multiple-choice questions to sharpen your Technical Programming knowledge and support exam preparation. Choose a topic below to get started.
| 551. |
What is the output of the following piece of code when executed in Python shell? >>> import collections >>> a=dict() >>> a=collections.defaultdict(str) >>> a['A'] |
| A. | An exception is thrown since the dictionary is empty |
| B. | ‘ ‘ |
| C. | ‘A’ |
| D. | 0 |
| Answer» C. ‘A’ | |
| 552. |
What is the output of the following piece of code when executed in Python shell? >>> import collections >>> a=dict() >>> a=collections.defaultdict(int) >>> a[1] |
| A. | 1 |
| B. | 0 |
| C. | An exception is thrown |
| D. | ‘ ‘ |
| Answer» C. An exception is thrown | |
| 553. |
What is the output of the following piece of code when executed in Python shell? >>> a=dict() >>> a[1] |
| A. | An exception is thrown since the dictionary is empty |
| B. | ‘ ‘ |
| C. | 1 |
| D. | 0 |
| Answer» B. ‘ ‘ | |
| 554. |
What is the output of the following piece of code when executed in Python shell? >>> a={i: 'A' + str(i) for i in range(5)} >>> a |
| A. | An exception is thrown |
| B. | {0: ‘A0’, 1: ‘A1’, 2: ‘A2’, 3: ‘A3’, 4: ‘A4’} |
| C. | {0: ‘A’, 1: ‘A’, 2: ‘A’, 3: ‘A’, 4: ‘A’} |
| D. | {0: ‘0’, 1: ‘1’, 2: ‘2’, 3: ‘3’, 4: ‘4’} |
| Answer» E. | |
| 555. |
What is the output of the following code? >>> a={"a":1,"b":2,"c":3} >>> b=dict(zip(a.values(),a.keys())) >>> b |
| A. | {‘a’: 1, ‘b’: 2, ‘c’: 3} |
| B. | An exception is thrown |
| C. | {‘a’: ‘b’: ‘c’: } |
| D. | {1: ‘a’, 2: ‘b’, 3: ‘c’} |
| Answer» E. | |
| 556. |
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» B. Returns False if dictionary is empty | |
| 557. |
What is the output of the following snippet of code? >>> b={} >>> all(b) |
| A. | { } |
| B. | False |
| C. | True |
| D. | An exception is thrown |
| Answer» D. An exception is thrown | |
| 558. |
What is the output of the following piece of code? >>> a={} >>> a.fromkeys([1,2,3],"check") |
| A. | Syntax error |
| B. | {1:”check”,2:”check”,3:”check”} |
| C. | “check” |
| D. | {1:None,2:None,3:None} |
| Answer» C. “check” | |
| 559. |
What is the output of the following snippet of code? >>> a={i: i*i for i in range(6)} >>> a |
| A. | Dictionary comprehension doesn’t exist |
| B. | {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6:36} |
| C. | {0: 0, 1: 1, 4: 4, 9: 9, 16: 16, 25: 25} |
| D. | {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25} |
| Answer» E. | |
| 560. |
What is the output of the following piece of code? >>> a={'B':5,'A':9,'C':7} >>> sorted(a) |
| A. | [‘A’,’B’,’C’]. |
| B. | [‘B’,’C’,’A’]. |
| C. | [5,7,9]. |
| D. | [9,5,7]. |
| Answer» B. [‘B’,’C’,’A’]. | |
| 561. |
What is the output of the following code? a={} a[2]=1 a[1]=[2,3,4] print(a[1][1]) |
| A. | [2,3,4]. |
| B. | 3 |
| C. | 2 |
| D. | An exception is thrown |
| Answer» C. 2 | |
| 562. |
What is the output of the following code? count={} count[(1,2,4)] = 5 count[(4,2,1)] = 7 count[(1,2)] = 6 count[(4,2,1)] = 2 tot = 0 for i in count: tot=tot+count[i] print(len(count)+tot) |
| A. | 25 |
| B. | 17 |
| C. | 16 |
| D. | Tuples can’t be made keys of a dictionary |
| Answer» D. Tuples can’t be made keys of a dictionary | |
| 563. |
What is the output of the following piece of code? >>> import collections >>> a=collections.Counter([3,3,4,5]) >>> b=collections.Counter([3,4,4,5,5,5]) >>> a&b |
| A. | Counter({3: 12, 4: 1, 5: 1}) |
| B. | Counter({3: 1, 4: 1, 5: 1}) |
| C. | Counter({4: 2}) |
| D. | Counter({5: 1}) |
| Answer» C. Counter({4: 2}) | |
| 564. |
What is the output of the following piece of code? >>> import collections >>> a=collections.Counter([2,2,3,3,3,4]) >>> b=collections.Counter([2,2,3,4,4]) >>> a|b |
| A. | Counter({3: 3, 2: 2, 4: 2}) |
| B. | Counter({2: 2, 3: 1, 4: 1}) |
| C. | Counter({3: 2}) |
| D. | Counter({4: 1}) |
| Answer» B. Counter({2: 2, 3: 1, 4: 1}) | |
| 565. |
What is the output of the following piece of code? >>>import collections >>> b=collections.Counter([2,2,3,4,4,4]) >>> b.most_common(1) |
| A. | Counter({4: 3, 2: 2, 3: 1}) |
| B. | {3:1} |
| C. | {4:3} |
| D. | [(4, 3)]. |
| Answer» E. | |
| 566. |
What is the output of the following piece of code? >>>import collections >>> a=collections.Counter([1,1,2,3,3,4,4,4]) >>> a |
| A. | {1,2,3,4} |
| B. | Counter({4, 1, 3, 2}) |
| C. | Counter({4: 3, 1: 2, 3: 2, 2: 1}) |
| D. | {4: 3, 1: 2, 3: 2, 2: 1} |
| Answer» D. {4: 3, 1: 2, 3: 2, 2: 1} | |
| 567. |
What is the output of the following snippet of code? a={} a['a']=1 a['b']=[2,3,4] print(a) |
| A. | Exception is thrown |
| B. | {‘b’: [2], ‘a’: 1} |
| C. | {‘b’: [2], ‘a’: [3]} |
| D. | {‘b’: [2, 3, 4], ‘a’: 1} |
| Answer» E. | |
| 568. |
What is the output of the following snippet of code? = {} a[1] = 1 a['1'] = 2 a[1.0]=4 count = 0 for i in a: count += a[i] print(count) |
| A. | An exception is thrown |
| B. | 3 |
| C. | 6 |
| D. | 2 |
| Answer» D. 2 | |
| 569. |
What is the output of the following snippet of code? test = {1:'A', 2:'B', 3:'C'} del test[1] test[1] = 'D' del test[2] print(len(test)) |
| A. | 0 |
| B. | 2 |
| C. | Error as the key-value pair of 1:’A’ is already deleted |
| D. | 1 |
| Answer» C. Error as the key-value pair of 1:’A’ is already deleted | |
| 570. |
What is the output of the following snippet of code? test = {1:'A', 2:'B', 3:'C'} test = {} print(len(test)) |
| A. | 0 |
| B. | None |
| C. | 3 |
| D. | An exception is thrown |
| Answer» B. None | |
| 571. |
What is the output of the following snippet of code? numbers = {} letters = {} comb = {} numbers[1] = 56 numbers[3] = 7 letters[4] = 'B' comb['Numbers'] = numbers comb['Letters'] = letters print(comb) |
| A. | Error, dictionary in a dictionary can’t exist |
| B. | Numbers’: {1: 56, 3: 7} |
| C. | {‘Numbers’: {1: 56}, ‘Letters’: {4: ‘B’}} |
| D. | {‘Numbers’: {1: 56, 3: 7}, ‘Letters’: {4: ‘B’}} |
| Answer» E. | |
| 572. |
What is the output of the following snippet of code? a = {} a[1] = 1 a['1'] = 2 a[1]=a[1]+1 count = 0 for i in a: count += a[i] print(count) |
| A. | 1 |
| B. | 2 |
| C. | 4 |
| D. | Error, the keys can’t be a mixture of letters and numbers |
| Answer» D. Error, the keys can’t be a mixture of letters and numbers | |
| 573. |
What is the output of the following snippet of code? total={} def insert(items): if items in total: total[items] += 1 else: total[items] = 1 insert('Apple') insert('Ball') insert('Apple') print (len(total)) |
| A. | 3 |
| B. | 1 |
| C. | 2 |
| D. | 0 |
| Answer» D. 0 | |
| 574. |
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» B. Removes all the key-value pairs | |
| 575. |
What is the output of the following snippet of code? >>> a={1:"A",2:"B",3:"C"} >>> del a |
| A. | method del doesn’t exist for the dictionary |
| B. | del deletes the values in the dictionary |
| C. | del deletes the entire dictionary |
| D. | del deletes the keys in the dictionary |
| Answer» D. del deletes the keys in the dictionary | |
| 576. |
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» D. Values of a dictionary can be a mixture of letters and numbers | |
| 577. |
Execute the following in Python shell? >>> 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» E. | |
| 578. |
. What is the output of the following code? a={1:"A",2:"B",3:"C"} for i in a: print(i,end=" ") |
| A. | 1 2 3 |
| B. | ‘A’ ‘B’ ‘C’ |
| C. | 1 ‘A’ 2 ‘B’ 3 ‘C’ |
| D. | Error, it should be: for i in a.items(): |
| Answer» B. ‘A’ ‘B’ ‘C’ | |
| 579. |
What is the output of the following code? a={1:5,2:3,3:4} print(a.pop(4,9)) |
| A. | 9 |
| B. | 3 |
| C. | Too many arguments for pop() method |
| D. | 4 |
| Answer» B. 3 | |
| 580. |
What is the output of the following code? a={1:5,2:3,3:4} a.pop(3) print(a) |
| A. | {1: 5} |
| B. | {1: 5, 2: 3} |
| C. | Error, syntax error for pop() method |
| D. | {1: 5, 3: 4} |
| Answer» C. Error, syntax error for pop() method | |
| 581. |
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» D. When duplicate keys encountered, the last assignment wins | |
| 582. |
What is the output of the following code? a={1:"A",2:"B",3:"C"} a.clear() print(a) |
| A. | None |
| B. | { None:None, None:None, None:None} |
| C. | {1:None, 2:None, 3:None} |
| D. | { } |
| Answer» E. | |
| 583. |
What is the output of the following code? a={1:"A",2:"B",3:"C"} b=a.copy() b[2]="D" print(a) |
| A. | Error, copy() method doesn’t exist for dictionaries |
| B. | {1: ‘A’, 2: ‘B’, 3: ‘C’} |
| C. | {1: ‘A’, 2: ‘D’, 3: ‘C’} |
| D. | “None” is printed |
| Answer» C. {1: ‘A’, 2: ‘D’, 3: ‘C’} | |
| 584. |
What is the output of the following code? a={1:"A",2:"B",3:"C"} b={4:"D",5:"E"} a.update(b) print(a) |
| A. | {1: ‘A’, 2: ‘B’, 3: ‘C’} |
| B. | Method update() doesn’t exist for dictionaries |
| C. | {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’} |
| D. | {4: ‘D’, 5: ‘E’} |
| Answer» D. {4: ‘D’, 5: ‘E’} | |
| 585. |
What is the output of the following code? a={1:"A",2:"B",3:"C"} a.setdefault(4,"D") print(a) |
| A. | {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’}. |
| B. | None. |
| C. | Error. |
| D. | [1,3,6,10]. |
| Answer» B. None. | |
| 586. |
What is the output of the following code? a={1:"A",2:"B",3:"C"} print(a.setdefault(3)) |
| A. | {1: ‘A’, 2: ‘B’, 3: ‘C’} |
| B. | C |
| C. | {1: 3, 2: 3, 3: 3} |
| D. | No method called setdefault() exists for dictionary |
| Answer» C. {1: 3, 2: 3, 3: 3} | |
| 587. |
What is the output of the following code? a={1:"A",2:"B",3:"C"} print(a.get(5,4)) |
| A. | Error, invalid syntax |
| B. | A |
| C. | 5 |
| D. | 4 |
| Answer» E. | |
| 588. |
What is the output of the following piece of code? a={1:"A",2:"B",3:"C"} print(a.get(1,4)) |
| A. | 1 |
| B. | A |
| C. | 4 |
| D. | Invalid syntax for get method |
| Answer» C. 4 | |
| 589. |
What is the output of the following 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» B. 1 2 3 | |
| 590. |
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» D. { } | |
| 591. |
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» C. Dictionaries aren’t ordered | |
| 592. |
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» D. Since “susan” is not a key in the set, Python raises a syntax error | |
| 593. |
Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which command do we use? |
| A. | d.size() |
| B. | len(d) |
| C. | size(d) |
| D. | d.len() |
| Answer» C. size(d) | |
| 594. |
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» D. del d(“john”:40) | |
| 595. |
What is the output? d = {"john":40, "peter":45} d["john"] |
| A. | 40 |
| B. | 45 |
| C. | “john” |
| D. | “peter” |
| Answer» B. 45 | |
| 596. |
What will be the output? d1 = {"john":40, "peter":45} d2 = {"john":466, "peter":45} d1 > d2 |
| A. | True |
| B. | False |
| C. | Error |
| D. | None |
| Answer» D. None | |
| 597. |
What will be the output? d1 = {"john":40, "peter":45} d2 = {"john":466, "peter":45} d1 == d2 |
| A. | True |
| B. | False |
| C. | None |
| D. | Error |
| Answer» C. None | |
| 598. |
What will be the output? d = {"john":40, "peter":45} "john" in d |
| A. | True |
| B. | False |
| C. | None |
| D. | Error |
| Answer» B. False | |
| 599. |
Read the code shown below carefully and pick out the keys? d = {"john":40, "peter":45} |
| A. | john”, 40, 45, and “peter” |
| B. | “john” and “peter” |
| C. | 40 and 45 |
| D. | d = (40:”john”, 45:”peter”) |
| Answer» C. 40 and 45 | |
| 600. |
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» E. | |