Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up

Which exception is raised when accessing a dictionary key that does not exist?

  1. A IndexError
  2. B KeyError
  3. C ValueError
  4. D AttributeError
Answer

KeyError

Use dict.get() to return a default instead, or collections.defaultdict when a missing key should create a default value.

All Python MCQs

Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up as