A

Admin • 825.56K Points
Coach

Q. What does `dict.setdefault('key', default)` do?

  • (A) Sets a new key only if it exists
  • (B) Returns the value if key exists; otherwise sets it to default
  • (C) Raises an error if key doesn’t exist
  • (D) Deletes the key

Explanation by: Admin
`setdefault()` returns the value if the key exists; if not, it inserts the key with the default value.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.