I've been using the following syntax in my code for checking the existence of a key:
if dict.get("key") is not None:
print "key found"
However, I have seen in other people's code the following syntax:
if 'key' in dict:
print "key found"
I was just wondering which way is best to express a dictionary key null check and if there is an advantage (if any) to using one over the other.
I saw the existing question addressing the similar question of what are the alternatives to using .get() but just want to know if there is any advantage between the two examples I provided.