+ 4

def(self,function: Callable)->Tuple[float,res]: what's this ?

I saw some libraries source code in Python , it have def(self,function: Callable)->Tuple[float,res]: I don't known what's this '' Can any one Explain It to me Give any hint about It '' Project Link --- https://github.com/Alfex4936/python-bigO-calculator

9th Oct 2021, 4:07 AM
Yesudasan Ebenezer
Yesudasan Ebenezer - avatar
5 Antworten
+ 6
Python allows you to attach metadata to functions describing their parameters and return values. def fn (self, function: Callable) -> Tuple[float,res]: : Callable tells people who are reading the program that function should be the Callable parameter. It is accessed as is fn.__ annotations __ ['function'] returns typing.Callable and has no meaning by itself. The same with the return value of the function -> Tuple[float,res] is fn.__ annotations __ ['return'] returns typing.Tuple[float, __main__.res] This is a function annotation that says that the function has Callable parameter and returns a tuple with floats or res objects (but not necessarily). https://code.sololearn.com/cHmdsW5sU23E/?ref=app
9th Oct 2021, 3:13 PM
Vitaly Sokol
Vitaly Sokol - avatar
+ 7
Type Annotations in 🐍 https://link.medium.com/i9Qrb5yydkb
9th Oct 2021, 3:47 PM
Janusz Bujak 🇵🇱 🇺🇦
Janusz Bujak 🇵🇱 🇺🇦 - avatar
+ 1
Its a function definition. The first line it looks like.
9th Oct 2021, 10:51 AM
Slick
Slick - avatar
+ 1
Callable is probably in exchange for () -> showes the return value Look at the code and see how its used
9th Oct 2021, 11:33 AM
Slick
Slick - avatar
0
Slick thanks for ans it , function : Callable means & what's ` -> ` explain this 🤥
9th Oct 2021, 11:32 AM
Yesudasan Ebenezer
Yesudasan Ebenezer - avatar