Computer Science

Which of the following will give error if d1 is as shown below?

d1 = {"a":1, "b":2, "c":3}
  1. print(len(d1))
  2. print(d1.get("b"))
  3. d1["a"] = 5
  4. None of these

Python Dictionaries

7 Likes

Answer

None of these

Reason — print(len(d1)) will print the length of d1 i.e. 3
print(d1.get("b")) will return the value of key "b" i.e. 2
d1["a"] = 5 will update the value of key "a" to 5.
Hence, all the expressions above will execute with no error.

Answered By

1 Like


Related Questions