Return Annotation
The return annotation is used in functions to indicate what type of data will be returned. This annotation is created using the -> syntax:
1234def addition(first: int, second: int) -> int: return first + second print(addition(15, 12))
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:.
Takk for tilbakemeldingene dine!
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Still meg spørsmål om dette emnet
Oppsummer dette kapittelet
Vis eksempler fra virkeligheten
Awesome!
Completion rate improved to 4.35
Return Annotation
Sveip for å vise menyen
The return annotation is used in functions to indicate what type of data will be returned. This annotation is created using the -> syntax:
1234def addition(first: int, second: int) -> int: return first + second print(addition(15, 12))
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:.
Takk for tilbakemeldingene dine!