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
7c91dbec
Kaydet (Commit)
7c91dbec
authored
Kas 01, 2012
tarafından
Andrew Svetlov
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge issue #14893: Add function annotation example to function tutorial.
Patch by Zachary Ware.
üst
0168d3d9
1491cbdf
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
0 deletions
+34
-0
controlflow.rst
Doc/tutorial/controlflow.rst
+34
-0
No files found.
Doc/tutorial/controlflow.rst
Dosyayı görüntüle @
7c91dbec
...
@@ -656,6 +656,40 @@ Here is an example of a multi-line docstring::
...
@@ -656,6 +656,40 @@ Here is an example of a multi-line docstring::
No, really, it doesn't do anything.
No, really, it doesn't do anything.
.. _tut-annotations:
Function Annotations
--------------------
.. sectionauthor:: Zachary Ware <zachary.ware@gmail.com>
.. index::
pair: function; annotations
single: -> (return annotation assignment)
:ref:`Function annotations <function>` are completely optional,
arbitrary metadata information about user-defined functions. Neither Python
itself nor the standard library use function annotations in any way; this
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
as a dictionary and have no effect on any other part of the function. Parameter
annotations are defined by a colon after the parameter name, followed by an
expression evaluating to the value of the annotation. Return annotations are
defined by a literal ``->``, followed by an expression, between the parameter
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
value annotated with nonsense::
>>> def f(ham: 42, eggs: int = 'spam') -> "Nothing to see here":
... print("Annotations:", f.__annotations__)
... print("Arguments:", ham, eggs)
...
>>> f('wonderful')
Annotations: {'eggs': <class 'int'>, 'return': 'Nothing to see here', 'ham': 42}
Arguments: wonderful spam
.. _tut-codingstyle:
.. _tut-codingstyle:
Intermezzo: Coding Style
Intermezzo: Coding Style
...
...
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