0% found this document useful (0 votes)
6 views11 pages

Dictionary

Uploaded by

isk61916
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views11 pages

Dictionary

Uploaded by

isk61916
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Dictionary

Methods
Ali Moustafa
@ali-moustafa2000
clear()
The "clear()" method removes all items from
the dictionary.

@ali-moustafa2000
copy()
The "copy()" method returns a shallow copy of the
dictionary.
NB: changes to the copy of the dictionary do not
affect the original dictionary.

@ali-moustafa2000
get()
The "get()" method returns the value of the
specified key. If the key is not present in the
dictionary, it will return "None" or a default value
specified as the second argument of the method.

@ali-moustafa2000
items()
The "items()" method returns a list of key-value
pairs in the dictionary.

@ali-moustafa2000
keys()
The "keys()" method returns a list of keys in the
dictionary.

@ali-moustafa2000
values()
The "values()" method Returns a list of values in
the dictionary.

@ali-moustafa2000
pop()
The "pop()" method removes and returns the
value of the specified key. If the key does not
exist, it raises a KeyError.
To avoid this, you can pass a default value to
be returned if the key is not found.

@ali-moustafa2000
popitem()
The "popitem()" method removes and returns
the last inserted key-value pair in the dictionary.
If the dictionary is empty, it raises a KeyError.

@ali-moustafa2000
setdefault()
The "setdefault()" method returns the value of the
specified key.
If the key does not exist, it inserts the key with the
specified default value.

@ali-moustafa2000
update()

The "update()" method updates the dictionary


with the specified key-value pairs.

@ali-moustafa2000

You might also like