Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
e039439e
Kaydet (Commit)
e039439e
authored
Ara 04, 1998
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Clarify evaluation of default arguments at def time with more text and
an example.
üst
c6e22902
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
2 deletions
+20
-2
ref7.tex
Doc/ref/ref7.tex
+20
-2
No files found.
Doc/ref/ref7.tex
Dosyayı görüntüle @
e039439e
...
...
@@ -304,8 +304,7 @@ executed only when the function is called.
When one or more top-level parameters have the form
\var
{
parameter
}
\code
{
=
}
\var
{
expression
}
, the function is said to have ``default
parameter values.''
\strong
{
Default parameter values are evaluated
when the function definition is executed.
}
For a parameter with a
parameter values.'' For a parameter with a
default value, the corresponding argument may be omitted from a call,
in which case the parameter's default value is substituted. If a
parameter has a default value, all following parameters must also have
...
...
@@ -315,6 +314,25 @@ expressed by the grammar.%
\code
{
def f(a=1, b)
}
is interpreted as
\code
{
def f(a=1, b=None)
}
.
}
\indexiii
{
default
}{
parameter
}{
value
}
\strong
{
Default parameter values are evaluated when the function
definition is executed.
}
This means that the expression is evaluated
once, when the function is defined, and that that same
``pre-computed'' value is used for each call. This is especially
important to understand when a default parameter is a mutable object,
such as a list or a dictionary: if the function modifies the object
(e.g. by appending an item to a list), the default value is in effect
modified. This is generally not what was intended. A way around this
is to use
\code
{
None
}
as the default, and explicitly test for it in
the body of the function, e.g.:
\begin{verbatim}
def whats
_
on
_
the
_
telly(penguin=None):
if penguin is None:
penguin = []
penguin.append("property of the zoo")
return penguin
\end{verbatim}
Function call semantics are described in more detail in section
\ref
{
calls
}
.
A function call always assigns values to all parameters mentioned in
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment