dictionary-question
Laura Creighton
lac at strakt.com
Wed Nov 21 13:38:19 EST 2001
I hate it when I am writing more than one message and I send the wrong one.
Sorry about that. I wasn't done yet. What I wanted to mention was
that you may be wanting setdefault, not get.
[GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> foo={'a': 1}
>>> foo.get("bar", 0)
0
>>> print foo
{'a': 1}
>>> foo.get("bar", 300)
300
>>> print foo
{'a': 1}
>>> foo.setdefault("bar",0)
0
>>> print foo
{'bar': 0, 'a': 1}
But you still can't assign to a function call.
>>> foo.setdefault("bar",0) +=1
SyntaxError: can't assign to function call
Laura
More information about the Python-list
mailing list