11. Hash

11.3 Get value using key

Hash stores key and value pair. We can pass a key to a hash and we can ask hash to return the value for the given key.

Here we have a hash where we have country name as key and country capital city as the value.

Let’s ask hash to print the capital city for USA.

Here we are doing the same thing but we are changing the key. We want to know what’s the capital city of country “France”.