mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Implement, test and document "key in dict" and "key not in dict".
I know some people don't like this -- if it's really controversial, I'll take it out again. (If it's only Alex Martelli who doesn't like it, that doesn't count as "real controversial" though. :-) That's why this is a separate checkin from the iterators stuff I'm about to check in next.
This commit is contained in:
parent
78fe5308b4
commit
0dbb4fba4c
5 changed files with 59 additions and 8 deletions
|
@ -867,9 +867,15 @@ arbitrary objects):
|
|||
{(1)}
|
||||
\lineiii{\var{a}.clear()}{remove all items from \code{a}}{}
|
||||
\lineiii{\var{a}.copy()}{a (shallow) copy of \code{a}}{}
|
||||
\lineiii{\var{a}.has_key(\var{k})}
|
||||
\lineiii{\var{k} \code{in} \var{a}}
|
||||
{\code{1} if \var{a} has a key \var{k}, else \code{0}}
|
||||
{}
|
||||
\lineiii{\var{k} not in \var{a}}
|
||||
{\code{0} if \var{a} has a key \var{k}, else \code{1}}
|
||||
{}
|
||||
\lineiii{\var{a}.has_key(\var{k})}
|
||||
{Equivalent to \var{k} \code{in} \var{a}}
|
||||
{}
|
||||
\lineiii{\var{a}.items()}
|
||||
{a copy of \var{a}'s list of (\var{key}, \var{value}) pairs}
|
||||
{(2)}
|
||||
|
@ -879,11 +885,11 @@ arbitrary objects):
|
|||
{(3)}
|
||||
\lineiii{\var{a}.values()}{a copy of \var{a}'s list of values}{(2)}
|
||||
\lineiii{\var{a}.get(\var{k}\optional{, \var{x}})}
|
||||
{\code{\var{a}[\var{k}]} if \code{\var{a}.has_key(\var{k})},
|
||||
{\code{\var{a}[\var{k}]} if \code{\var{k} in \var{a}}},
|
||||
else \var{x}}
|
||||
{(4)}
|
||||
\lineiii{\var{a}.setdefault(\var{k}\optional{, \var{x}})}
|
||||
{\code{\var{a}[\var{k}]} if \code{\var{a}.has_key(\var{k})},
|
||||
{\code{\var{a}[\var{k}]} if \code{\var{k} in \var{a}}},
|
||||
else \var{x} (also setting it)}
|
||||
{(5)}
|
||||
\lineiii{\var{a}.popitem()}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue