Which is the correct form of declaration of dictionary? (i) Day={1:’monday’,2:’tuesday’,3:’wednesday’} (ii) Day=(1;’monday’,2;’tuesday’,3;’wednesday’) (iii) Day=[1:’monday’,2:’tuesday’,3:’wednesday’] (iv) Day={1’monday’,2’tuesday’,3’wednesday’]
Answers
Answer:
(i) Day={1:’monday’,2:’tuesday’,3:’wednesday’}
Explanation:
It's cause dictionaries have only flower brackets on both the ends.
Day = {1: 'monday', 2: 'tuesday', 3: 'wednesday'} is the correct form of declaration of dictionary
(i) Day = {1: 'monday', 2: 'tuesday', 3: 'wednesday'}
Let's correct the question.
Which is the correct form of declaration of dictionary?
(i) Day = {1: 'monday', 2: 'tuesday', 3: 'wednesday'}
(ii) Day = (1; 'monday', 2; 'tuesday', 3; 'wednesday')
(iii) Day = [1: 'monday', 2: 'tuesday’, 3: 'wednesday']
(iv) Day = {1'monday', 2'tuesday', 3'wednesday']
Extra Information
Dictionary in Python is used to store data values in an unordered collection. For storing data in a dictionary keys are used. It's like a key: value pair in which data is held by unique keys.
In this Day = {1: 'monday', 2: 'tuesday', 3: 'wednesday'}
Day is a dictionary that has keys 1, 2 and 3 and its values are monday, tuesday, and wednesday respectively.
Example
d1 = {"abc":5,"def":6,"ghi":7}
d1 is a dictionary that has keys abc, def, and ghi and its values are 5, 6, and 7 respectively.
Python is created by Guido van Rossum and came into existence in 1991. It is a high-level and general programming language. It is a very lucid programming language as it has a good language construct and object-oriented approach. It is dynamically typed and garbage-collected.