###### 18.11.2024
ID:473 | Lothar | 17:25 |

Python Annotations

# Python Annotations ##### Funktions-Definitionen mit nachfolgendem `->` und Datentyp vor dem `:` {h5_1} ###### ## Beispiel dazu
~~~python
def f(x) -> int:
    return int(x)
~~~
## Erklärung Das `-> int` besagt nur dass die Funktion einen ›Integer‹ zurückgeben *soll*. Tatsächlich wird dies dadurch aber *nicht* erzwungen, es ist **nur ein Hinweis**. Man nennt so festgelegte Hinweise ein ›return annotation‹. Innerhalb des Codes kann man darauf Zugriff per:
~~~python
f.__annotations__['return']
~~~
Wie man sieht, handelt es sich um ein ›dictionary‹. Gefunden habe ich das alles [hier](https://stackoverflow.com/questions/14379753/what-does-mean-in-python-function-definitions) ## weiter
main_LA - footer