+ 4

Function Annotations What is it?

And what does mean this sign in Python " ->" I don't understand English well. Thank you for using simple words

10th May 2021, 12:43 AM
Amir
Amir - avatar
6 Answers
+ 4
-> is used to signify the expected return type from a function in python. It is optional. https://www.python.org/dev/peps/pep-3107/ Example: https://code.sololearn.com/c9scA7o07x8n/?ref=app
10th May 2021, 12:59 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
Let's say we have a function that takes 2 numbers, a and b as parameters. You expect the numbers to be of type int so you annotate int as their type like; def add(a: int, b: int): Now this function should also return a value of type int, so you declare so like; def add(a: int, b: int) -> int: return a + b Of course all this is optional and you could also just write the function like; def add(a, b): return a + b I suggest you thoroughly read through the link to the PEP I posted above for a better understanding and explanation.
10th May 2021, 1:16 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
ChaoticDawg Thank you so much.🙏
10th May 2021, 1:19 AM
Amir
Amir - avatar
0
anonymous function or arrow function
10th May 2021, 12:53 AM
Alfonso FarĂ­as
Alfonso FarĂ­as - avatar
0
Both😁
10th May 2021, 12:54 AM
Amir
Amir - avatar
0
ChaoticDawg Thank you. But in fact, I didn't get it. đŸ€Šâ€â™‚ïž
10th May 2021, 1:08 AM
Amir
Amir - avatar