Kaydet (Commit) 8141cf5c authored tarafından Guido van Rossum's avatar Guido van Rossum

Barry's patch to document the new setdefault() method. Slightly

clarified the summary for default() in the table to indicate the side
effect.
üst 79c9b17d
...@@ -591,6 +591,10 @@ arbitrary objects): ...@@ -591,6 +591,10 @@ arbitrary objects):
{\code{\var{a}[\var{k}]} if \code{\var{a}.has_key(\var{k})}, {\code{\var{a}[\var{k}]} if \code{\var{a}.has_key(\var{k})},
else \var{x}} else \var{x}}
{(4)} {(4)}
\lineiii{\var{a}.setdefault(\var{k}\optional{, \var{x}})}
{\code{\var{a}[\var{k}]} if \code{\var{a}.has_key(\var{k})},
else \var{x} (also setting it)}
{(5)}
\end{tableiii} \end{tableiii}
\noindent \noindent
...@@ -611,6 +615,10 @@ correspond. This allows the creation of \code{(\var{value}, ...@@ -611,6 +615,10 @@ correspond. This allows the creation of \code{(\var{value},
\item[(4)] Never raises an exception if \var{k} is not in the map, \item[(4)] Never raises an exception if \var{k} is not in the map,
instead it returns \var{x}. \var{x} is optional; when \var{x} is not instead it returns \var{x}. \var{x} is optional; when \var{x} is not
provided and \var{k} is not in the map, \code{None} is returned. provided and \var{k} is not in the map, \code{None} is returned.
\item[(5)] \function{setdefault()} is like \function{get()}, except
that if \var{k} is missing, \var{x} is both returned and inserted into
the dictionary as the value of \var{k}.
\end{description} \end{description}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment