[Tutor] Question about dictionary method get()
Dick Moores
rdmoores at gmail.com
Mon Jun 28 07:25:08 EDT 2004
This is probably trivial, but it makes me suspect that there's
something I don't understand about "None".
In _Python in a Nutshell_, on p. 50, I find, under "Dictionary Methods":
D.get(k[,x]) -- Returns D[k] if k is a key in D, otherwise
returns x (or None, if x is not given)
But in my simple
D = {'a': 'first letter', 'b': 'second letter', 'c': 'third letter',
'z': 'last letter'}
D.get("v") returns nothing, not "None". (with version 2.3.4)
The .chm file I have of the Python documentation for 2.3, it says
a.get(k[, x]) -- a[k] if k in a, else x
Does this imply that that my D.get("v") will return nothing, not
"None", and that there might be an error in the wonderful _Python in a
Nutshell_? Or am I just confused about something here? Or is this a
version difference?
Uh, oh. I just now tried print D.get("v") and did get "None".
Then why not with the plain D.get("v") ? Maybe I've found the
source of my confusion?
Thanks again,
Dick Moores
More information about the Tutor
mailing list