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 the country name as the key and the country capital city as the value.

Key Value
USA Washington D.C.
England London
France Paris

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”.