+ 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 ответов
+ 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