Bootstrap FreeKB - Python (Scripting) - hash has_key
Python (Scripting) - hash has_key

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter 9abedc in the box below so that we can be sure you are a human.