Answers for "how to check if and key exists in a dictioanry python"

10

python check if key exists

d = {"apples": 1, "banannas": 4}
# Preferably use .keys() when searching for a key
if "apples" in d.keys():
  print(d["apples"])
Posted by: Guest on May-08-2020

Code answers related to "how to check if and key exists in a dictioanry python"

Python Answers by Framework

Browse Popular Code Answers by Language