dict and __cmp__() question
Alex
lidenalex at yahoo.se
Wed Sep 7 03:42:34 EDT 2005
Entering
>>> help(dict)
Help on class dict in module __builtin__:
class dict(object)
| dict() -> new empty dictionary.
| dict(mapping) -> new dictionary initialized from a mapping object's
| (key, value) pairs.
| dict(seq) -> new dictionary initialized as if via:
| d = {}
| for k, v in seq:
| 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:
|
| __cmp__(...)
| x.__cmp__(y) <==> cmp(x,y)
|
| __contains__(...)
| D.__contains__(k) -> True if D has a key k, else False
snip
| update(...)
| D.update(E, **F) -> None. Update D from E and F: for k in E:
D[k] = E[k]
| (if E has keys else: for (k, v) in E: D[k] = v) then: for k in
F: D[k] = F[k]
|
| values(...)
| D.values() -> list of D's values
Now I understand methods like update(...) and values(...), for instance
>>> D={'a':1, 'b':2}
>>> D.values()
[1, 2]
>>>
But what are those with double underscore? For instance __cmp__(...)?
I tried
>>> D.cmp('a','b')
Traceback (most recent call last):
File "<pyshell#7>", line 1, in -toplevel-
D.cmp('a','b')
AttributeError: 'dict' object has no attribute 'cmp'
>>>
Alex
More information about the Python-list
mailing list