Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Return Annotation | Annotations
Mastering Python: Annotations, Errors and Environment

bookReturn Annotation

The return annotation is used in functions to indicate what type of data will be returned. This annotation is created using the -> syntax:

1234
def addition(first: int, second: int) -> int: return first + second print(addition(15, 12))
copy

Return annotations are helpful for both function users and writers, as they indicate if the function is returning an unexpected data type:

The division operator (/) returns a float value, but if we expect an int, the return annotation can help us identify this potential bug in our function.

Note

To create the return annotation, you need to use the -> and type (e.g., str) between closed parenthesis ) and colon :.

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 3

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Awesome!

Completion rate improved to 4.35

bookReturn Annotation

Veeg om het menu te tonen

The return annotation is used in functions to indicate what type of data will be returned. This annotation is created using the -> syntax:

1234
def addition(first: int, second: int) -> int: return first + second print(addition(15, 12))
copy

Return annotations are helpful for both function users and writers, as they indicate if the function is returning an unexpected data type:

The division operator (/) returns a float value, but if we expect an int, the return annotation can help us identify this potential bug in our function.

Note

To create the return annotation, you need to use the -> and type (e.g., str) between closed parenthesis ) and colon :.

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 3
some-alt