
by
Jeremy Canfield | Updated February 7th, 2019
The has_key opertor checks to see if a has contains a key. For example, let's consider a hash named "hash" that contains a key called "foo".
hash = {'foo': 'bar'}
An if else statement can be used to print text identifying if the hash contains a key named foo.
if hash.has_key('foo'):
print("hash contains a key named foo")
else
print("hash does not contain a key named foo")