+ 1

Python functions

Why are functions written like this def customer (Id : int, phone : int) -> int What's the use of the colon in the argument? Why is there a -> int at the function declaration?

23rd Jul 2021, 6:09 AM
Sudo
Sudo - avatar
7 Answers
+ 6
Slick I don't know for sure either, but I think this is the return type.
23rd Jul 2021, 6:18 AM
đŸ‡ș🇩 GUMBALL đŸ‡ș🇩 [Dead account]
+ 3
Yup, seems like you coulda done that from the start, instead of letting us do that for you and then marking your own answer as best.
23rd Jul 2021, 6:50 AM
Slick
Slick - avatar
+ 2
the ": int" part is just to tell someone who's going over the code what type the parameter is. similar to c declaration void print_somethin(char *buffer) except the type is after. no idea about the "-> int" EDIT: just looked it up and Gᑌᗰᗷᗩá’Șá’Ș is right!
23rd Jul 2021, 6:14 AM
Slick
Slick - avatar
+ 1
Sudo Ok according to this module, Id and phone are arguments and int is type of both arguments and -> int is return type.
23rd Jul 2021, 8:41 AM
AÍąJ
AÍąJ - avatar
0
I just checked it up and id : int is type hint while -> int is return type Thanks Gᑌᗰᗷᗩá’Șá’Ș Slick
23rd Jul 2021, 6:46 AM
Sudo
Sudo - avatar
0
Is this a python functions syntax. If so then in which version because I didn't find this type of function definition in python.
23rd Jul 2021, 6:46 AM
AÍąJ
AÍąJ - avatar
0
AÍąJ it's a syntax accompanied by typing module
23rd Jul 2021, 7:07 AM
Sudo
Sudo - avatar