KnowledgeBoat Logo
|

Computer Science

Which of the following will result in an error for a given valid dictionary D?

  1. D + 3
  2. D * 3
  3. D + {3 : "3"}
  4. D.update( {3 : "3"})
  5. D.update { {"3" : 3}}
  6. D.update("3" : 3)

Python Dictionaries

23 Likes

Answer

  1. D + 3 — This will result in an error as dictionary does not support + operation.
  2. D * 3 — This will result in an error as dictionary does not support * operation.
  3. D + {3 : "3"} — This will result in an error as dictionary does not support + operation..
  4. D.update( {3 : "3"}) — This will execute with no error since valid dictionary is passed to update( ) method.
  5. D.update { {"3" : 3}} — This will result in an error since update( ) method syntax used here is invalid.
  6. D.update("3" : 3) — This will result in an error since update( ) method always takes dictionary as it arguments which is not passed here. Hence it will lead to an error.

Answered By

12 Likes


Related Questions