A dictionary is a collection of key-value pairs or items that can be referred to using a key name.
In a dictionary…
Duplicate items are
Values can be of any data type and duplicated, whereas keys can’t be repeated and must be immutable.
Dictionary keys are case sensitive.
update()
method**
methodd1
) with the values set as fruit names.d3
) and give it the same value as the dictionary (d1
).d1
with key values 4,5,6 and other fruits as values.d4
) and give it the dictionary (d2
).d1
) with the values of d2
merge and the two dictionaries’ items are updated.update
method, we update d2 with values of d1, basically merging the two dictionary items as updated elements.d3
and d4
dictionary).d1 = {1:"cucumber",2:"peas",3:"carrot"} print(d1) d3 = d1 d2 = {4:"Pineapple",5:"Mango",6:"Apple"} d4 = d2 d1.update(d2) print(d1) d2.update(d1) print(d2) new = {**d3,**d4} print(new)
RELATED TAGS
CONTRIBUTOR
View all Courses