+ 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
6 Respostas
+ 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
+ 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.
+ 1
ChaoticDawg
Thank you so much.🙏
0
anonymous function or arrow function
0
Both😁
0
ChaoticDawg
Thank you.
But in fact, I didn't get it. 🤦♂️