Python (Scripting) - hash has_key

by
Jeremy Canfield |
Updated: March 09 2020
| Python (Scripting) articles
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")
Did you find this article helpful?
If so, consider buying me a coffee over at