December 2000
Intermediate to advanced
816 pages
16h 57m
English
Table 7.1 lists the methods for dictionary objects. The clear(), copy(), get(), and update() methods were added recently in Python 1.5. setdefault() was introduced in 2.0.
| dictionary method | Operation |
|---|---|
| dict.clear[a]() | removes all elements of dictionary dict |
| dict.copy[a]() | returns a (shallow [b]) copy of dictionary dict |
| dict.get(key, default=None)[a] | for key key, returns value or default if key not in dictionary (note that default's default is None) |
| dict.has_key(key) | returns 1 if key in dictionary dict, 0 otherwise |
| dict.items() | returns a list of dict's (key, value) tuple pairs |
| dict.keys() | returns list of dictionary dict's keys |
| dict.setdefault key, default=None)[c] | similar to get(), but will set dict[key ... |
Read now
Unlock full access