0% found this document useful (0 votes)
2 views6 pages

Dictionary in Python

The document details the functionality of the Python dictionary class, including various ways to create a dictionary and its methods for manipulating key-value pairs. It outlines methods for checking key existence, deleting items, and retrieving values, among others. Additionally, it describes class and static methods related to dictionary creation and manipulation.

Uploaded by

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

Dictionary in Python

The document details the functionality of the Python dictionary class, including various ways to create a dictionary and its methods for manipulating key-value pairs. It outlines methods for checking key existence, deleting items, and retrieving values, among others. Additionally, it describes class and static methods related to dictionary creation and manipulation.

Uploaded by

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

Dictionary Function Details

class dict(object)

| dict() -> new empty dictionary

| dict(mapping) -> new dictionary initialized from a mapping object's

| (key, value) pairs

| dict(iterable) -> new dictionary initialized as if via:

| d = {}

| for k, v in iterable:

| d[k] = v

| dict(**kwargs) -> new dictionary initialized with the name=value pairs

| in the keyword argument list. For example: dict(one=1, two=2)

| Methods defined here:

| __contains__(self, key, /)

| True if the dictionary has the specified key, else False.

| __delitem__(self, key, /)

| Delete self[key].

| __eq__(self, value, /)

| Return self==value.
|

| __ge__(self, value, /)

| Return self>=value.

| __getattribute__(self, name, /)

| Return getattr(self, name).

| __getitem__(self, key, /)

| Return self[key].

| __gt__(self, value, /)

| Return self>value.

| __init__(self, /, *args, **kwargs)

| Initialize self. See help(type(self)) for accurate signature.

| __ior__(self, value, /)

| Return self|=value.

| __iter__(self, /)

| Implement iter(self).

| __le__(self, value, /)
| Return self<=value.

| __len__(self, /)

| Return len(self).

| __lt__(self, value, /)

| Return self<value.

| __ne__(self, value, /)

| Return self!=value.

| __or__(self, value, /)

| Return self|value.

| __repr__(self, /)

| Return repr(self).

| __reversed__(self, /)

| Return a reverse iterator over the dict keys.

| __ror__(self, value, /)

| Return value|self.

|
| __setitem__(self, key, value, /)

| Set self[key] to value.

| __sizeof__(self, /)

| Return the size of the dict in memory, in bytes.

| clear(self, /)

| Remove all items from the dict.

| copy(self, /)

| Return a shallow copy of the dict.

| get(self, key, default=None, /)

| Return the value for key if key is in the dictionary, else default.

| items(self, /)

| Return a set-like object providing a view on the dict's items.

| keys(self, /)

| Return a set-like object providing a view on the dict's keys.

| pop(self, key, default=<unrepresentable>, /)

| D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
|

| If the key is not found, return the default if given; otherwise,

| raise a KeyError.

| popitem(self, /)

| Remove and return a (key, value) pair as a 2-tuple.

| Pairs are returned in LIFO (last-in, first-out) order.

| Raises KeyError if the dict is empty.

| setdefault(self, key, default=None, /)

| Insert key with a value of default if key is not in the dictionary.

| Return the value for key if key is in the dictionary, else default.

| update(...)

| D.update([E, ]**F) -> None. Update D from mapping/iterable E and F.

| If E is present and has a .keys() method, then does: for k in E.keys(): D[k] =
E[k]

| If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v

| In either case, this is followed by: for k in F: D[k] = F[k]

| values(self, /)
| Return an object providing a view on the dict's values.

| ----------------------------------------------------------------------

| Class methods defined here:

| __class_getitem__(object, /)

| See PEP 585

| fromkeys(iterable, value=None, /)

| Create a new dictionary with keys from iterable and values set to value.

| ----------------------------------------------------------------------

| Static methods defined here:

| __new__(*args, **kwargs)

| Create and return a new object. See help(type) for accurate signature.

| ----------------------------------------------------------------------

| Data and other attributes defined here:

| __hash__ = None

You might also like