L Linh Chi New member Sep 20, 2021 #1 What will be the output of the following Python code? Code: >>> import collections >>> a=dict() >>> a=collections.defaultdict(int) >>> a[1] A. 1 B. 0 C. An exception is thrown D. ‘ ‘
What will be the output of the following Python code? Code: >>> import collections >>> a=dict() >>> a=collections.defaultdict(int) >>> a[1] A. 1 B. 0 C. An exception is thrown D. ‘ ‘
T Tạ Bích Hạnh Member Sep 20, 2021 #2 Answer: b Explanation: The statement a=collections.defaultdict(int) gives the default value of 0 (since int data type is given within the parenthesis) even if the keys don’t exist in the dictionary. Upvote 0 Downvote
Answer: b Explanation: The statement a=collections.defaultdict(int) gives the default value of 0 (since int data type is given within the parenthesis) even if the keys don’t exist in the dictionary.