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
f3b990e4
Kaydet (Commit)
f3b990e4
authored
Nis 13, 2015
tarafından
Zachary Ware
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #23932: Update the tutorial section on function annotations.
Patch by Juti Noppornpitak.
üst
bb5dbf84
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
11 deletions
+10
-11
controlflow.rst
Doc/tutorial/controlflow.rst
+10
-11
No files found.
Doc/tutorial/controlflow.rst
Dosyayı görüntüle @
f3b990e4
...
@@ -673,11 +673,9 @@ Function Annotations
...
@@ -673,11 +673,9 @@ Function Annotations
pair: function; annotations
pair: function; annotations
single: -> (return annotation assignment)
single: -> (return annotation assignment)
:ref:`Function annotations <function>` are completely optional,
:ref:`Function annotations <function>` are completely optional metadata
arbitrary metadata information about user-defined functions. Neither Python
information about the types used by user-defined functions (see :pep:`484`
itself nor the standard library use function annotations in any way; this
for more information).
section just shows the syntax. Third-party projects are free to use function
annotations for documentation, type checking, and other uses.
Annotations are stored in the :attr:`__annotations__` attribute of the function
Annotations are stored in the :attr:`__annotations__` attribute of the function
as a dictionary and have no effect on any other part of the function. Parameter
as a dictionary and have no effect on any other part of the function. Parameter
...
@@ -686,16 +684,17 @@ expression evaluating to the value of the annotation. Return annotations are
...
@@ -686,16 +684,17 @@ expression evaluating to the value of the annotation. Return annotations are
defined by a literal ``->``, followed by an expression, between the parameter
defined by a literal ``->``, followed by an expression, between the parameter
list and the colon denoting the end of the :keyword:`def` statement. The
list and the colon denoting the end of the :keyword:`def` statement. The
following example has a positional argument, a keyword argument, and the return
following example has a positional argument, a keyword argument, and the return
value annotated
with nonsense
::
value annotated::
>>> def f(ham:
42, eggs: int = 'spam') -> "Nothing to see here"
:
>>> def f(ham:
str, eggs: str = 'eggs') -> str
:
... print("Annotations:", f.__annotations__)
... print("Annotations:", f.__annotations__)
... print("Arguments:", ham, eggs)
... print("Arguments:", ham, eggs)
... return ham + ' and ' + eggs
...
...
>>> f('
wonderful
')
>>> f('
spam
')
Annotations: {'
eggs': <class 'int'>, 'return': 'Nothing to see here', 'ham': 42
}
Annotations: {'
ham': <class 'str'>, 'return': <class 'str'>, 'eggs': <class 'str'>
}
Arguments:
wonderful spam
Arguments:
spam eggs
'spam and eggs'
.. _tut-codingstyle:
.. _tut-codingstyle:
...
...
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