### questions

Title
###### Which of the following statements create a dictionary

Which of the following statements create a dictionary?

1. d = {}
2. d = {“john”:40, “peter”:45}
3. d = {40:”john”, 45:”peter”}
4. All of the mentioned
###### Read the code shown below carefully and pick out the keys

Read the code shown below carefully and pick out the keys?

``d = {"john":40, "peter":45}``

1. “john”, 40, 45, and “peter”
2. “john” and “peter”
3. 40 and 45
4. d = (40:”john”, 45:”peter”)
###### What will be the output

What will be the output

``````d = {"john":40, "peter":45}"
john" in d``````

1. True
2. False
3. None
4. Error
###### What will be the output

What will be the output

``````d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 == d2``````

1. True
2. False
3. None
4. Error
###### What will be the output

What will be the output?

``````d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 > d2``````

1. True
2. False
3. None
4. Error
###### What is the output

What is the output?

``````d = {"john":40, "peter":45}
d["john"]``````

1. 40
2. 45
3. “john”
4. “peter”
###### Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we us

Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use

1. d.delete(“john”:40)
2. d.delete(“john”)
3. del d[“john”].
4. del d(“john”:40)
###### Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which command do we use

Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which command do we use?

1. d.size()
2. len(d)
3. size(d)
4. d.len()
###### What will be the output

What will be the output?

``````d = {"john":40, "peter":45}
print(list(d.keys()))``````

1. [“john”, “peter”].
2. [“john”:40, “peter”:45].
3. (“john”, “peter”)
4. (“john”:40, “peter”:45)
###### Suppose d = {“john”:40, “peter”:45}, what happens when we try to retrieve a value using the expression d[“susan”]

Suppose d = {“john”:40, “peter”:45}, what happens when we try to retrieve a value using the expression d[“susan”]?

1. Since “susan” is not a value in the set, Python raises a KeyError exception
2. It is executed fine and no exception is raised, and it returns None
3. Since “susan” is not a key in the set, Python raises a KeyError exception
4. Since “susan” is not a key in the set, Python raises a syntax error
###### Which of these about a dictionary is false

Which of these about a dictionary is false?

1. The values of a dictionary can be accessed using keys
2. The keys of a dictionary can be accessed using values
3. Dictionaries aren’t ordered
4. Dictionaries are mutable
###### Which of the following is not a declaration of the dictionary

Which of the following is not a declaration of the dictionary?

1. {1: ‘A’, 2: ‘B’}
2. dict([[1,”A”],[2,”B”]])
3. {1,”A”,2”B”}
4. { }
###### What is the output of the following code

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=" ")``````

1. 1 A 2 B 3 C
2. 1 2 3
3. A B C
4. 1:”A” 2:”B” 3:”C”
###### What is the output of the following piece of code

What is the output of the following piece of code?

``````a={1:"A",2:"B",3:"C"}
print(a.get(1,4))``````

1. 1
2. A
3. 4
4. Invalid syntax for get method
###### What is the output of the following code

What is the output of the following code?

``````a={1:"A",2:"B",3:"C"}
print(a.get(5,4))``````

1. Error, invalid syntax
2. A
3. 5
4. 4
###### What is the output of the following code

What is the output of the following code?

``````a={1:"A",2:"B",3:"C"}
print(a.setdefault(3))``````

1. {1: ‘A’, 2: ‘B’, 3: ‘C’}
2. C
3. {1: 3, 2: 3, 3: 3}
4. No method called setdefault() exists for dictionary
###### What is the output of the following code

What is the output of the following code?

``````a={1:"A",2:"B",3:"C"}
a.setdefault(4,"D")
print(a)``````

1. {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’}.
2. None
3. Error.
4. [1,3,6,10].
###### What is the output of the following code

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)``````

1. {1: ‘A’, 2: ‘B’, 3: ‘C’}
2. Method update() doesn’t exist for dictionaries
3. {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’}
4. {4: ‘D’, 5: ‘E’}
###### What is the output of the following code

What is the output of the following code?

``````a={1:"A",2:"B",3:"C"}
b=a.copy()
b="D"
print(a)``````

1. Error, copy() method doesn’t exist for dictionaries
2. {1: ‘A’, 2: ‘B’, 3: ‘C’}
3. {1: ‘A’, 2: ‘D’, 3: ‘C’}
4. “None” is printed
###### What is the output of the following code

What is the output of the following code?

``````a={1:"A",2:"B",3:"C"}
a.clear()
print(a)``````

1. None
2. { None:None, None:None, None:None}
3. {1:None, 2:None, 3:None}
4. { }
###### total MCQs: 124 MCQs

##### 124 Views

##### 116  