Python Dictionary 3

Asked

Viewed 81 times

1

Hello, could someone help me understand why 8 is the correct answer? From now on, thank you very much. Resposta 8 em anexo

1 answer

3


The get(key, default) function returns the value in the map according to the key key specific.

On the map we have the following keys: 1, 2, 3, 4, and their values are as follows:: 1, 1, 2, 3

In the example:

fib.get(4, 0)

Will recover the value who holds the key 4, in the case, the value 3. If it did not exist in the key map with this value would be returned the value 0.

fib.get(7, 5)

Will recover the value who holds the key 7, as there is no value on the map with this key will be returned the default value 5

As a result then we have 3 + 5 = 8

A teaching reference: https://www.tutorialspoint.com/python/dictionary_get.htm

  • Thank you very much. Now I understand perfectly. Vlw.

  • I am happy to know that I could help. I thank you for accepting the answer. Good studies!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.