Python

Python

Dictionary has 8 Questions
Suppose d = {"john"?:40, "peter"?:45}, what happens when retieving a value using d["susan"?]?

Since "susan"? is not a value in the set, Python raises a KeyError exception.
It is executed fine and no exception is raised, and it returns None.
Since "susan"? is not a key in the set, Python raises a KeyError exception.
Since "susan"? is not a key in the set, Python raises a syntax error.
What are the keys?
  1. d = {"john":40, "peter":45}

"john"?, 40, 45, and "peter"?
"john"? and "peter"?
40 and 45
d = (40:"?john"?, 45:"?peter"?)
What will be the output?
  1. d = {"john":40, "peter":45}
  2. "john" in d

True
False
None
Error
What will be the output?
  1. d1 = {"john":40, "peter":45}
  2. d2 = {"john":466, "peter":45}
  3. d1 > d2

True
False
Error
None
What is the output?
  1. d = {"john":40, "peter":45}
  2. d["john"]

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

d.delete("john"?:40)
d.delete("john"?)
del d["john"?]
del d("john"?:40)
Suppose d = {"john"?:40, "peter"?:45}, to obtain the number of entries in dictionary what command do we use

d.size()
len(d)
size(
d) d.len()
What will be the output?
  1. d = {"john":40, "peter":45}
  2. print(list(d.keys()))

["john"?, "peter"?]
["john"?:40, "peter"?:45]
("john"?, "peter"?)
("john"?:40, "peter"?:45)