Dictionary Keys

Dictionaries
 
do
 
not
 
have 
indexing, 
but 
they 
have 
keys, 
which 
are 
very 
similar 
to 
indexing. 
Adding 
values 
to 
a 
dictionary 
can 
be 
done 
in 
the 
same 
way 
using 
keys 
like 
it 
is 
done 
with 
indexing. 
If 
you 
use 
the 
same 
key 
again 
and 
give 
another 
value, 
it 
will 
remove
 
the 
old 
value 
and 
store 
the 
new 
value 
for 
the 
key.
dict_name[key] = value
dict_1 = {}
#empty dictionary
dict_1['mobile'] = 'iPhone'
print(dict_1)
dict_1['mobile'] = 'OnePlus'
print(dict_1)

Check if a Key is present

The
 
'in'
 
feature 
can 
be 
used 
to 
check 
whether 
a 
key 
is 
present 
in 
a 
Dictionary
.
As 
it 
is 
a 
conditional 
statement, 
if 
the 
key 
is 
present 
it 
returns 
True 
else 
it 
returns 
False
.
print(key in dict_name)
dict_1 = { 'Theo' : 7717234567, 'Zo' : 8211132111 }
print('Zo' in dict_1)
print('Tyra' in dict_1)