From 5ee74650f16121f147dbf70469940925a14f8ea9 Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 7 Nov 2018 10:32:45 -0800 Subject: [PATCH] Update index.md with has_key() (#21093) Adding has_key() method to python dictionaries --- .../english/python/data-structures/dictionaries/index.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/guide/english/python/data-structures/dictionaries/index.md b/guide/english/python/data-structures/dictionaries/index.md index 711ae14250..3cd14346e9 100644 --- a/guide/english/python/data-structures/dictionaries/index.md +++ b/guide/english/python/data-structures/dictionaries/index.md @@ -65,6 +65,15 @@ It's easy to add key-value pairs to an existing dictionary: >>> club_names [1910, 1875] ``` +**`has_key`** is a built-in *method* that can be used to check if a *key* exists in the dictionary. +```python + >>> items = {'a': 'apple', 'b': 'banana', 'c': 'cat'} + >>> items.has_key('a') + True + >>> items.has_key('d') + False +``` + Yet another way of creating dictionary is using the **`dict()`** method: ```python >>> players = dict( [('messi','argentina'), ('ronaldo','portugal'), ('kaka','brazil')] ) # sequence of key-value pair is passed