FreeKB - has_key in Python
has_key in Python

Home > Search


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")

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




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




Comments