Similar Collections


    No collections found

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
discuss
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”)
discuss
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
discuss
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
discuss
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
discuss
What is the output

What is the output?

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

  1. 40
  2. 45
  3. “john”
  4. “peter”
discuss
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)
discuss
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()
discuss
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)
discuss
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
discuss
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
discuss
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. { }
discuss
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”
discuss
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
discuss
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
discuss
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
discuss
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].
discuss
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’}
discuss
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[2]="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
discuss
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. { }
discuss
total MCQs: 124

MCQs

124

Views

116

Best Answers

299

Points

5