Python apply function

Calling cusom function using apply function

Is that possible to call any function uisng function name as argument?

yes, apply function is available in python programming.

__builtin__ module is automatically available in python modules and no need to manually import. Python will use this module when necessary

apply function syntax:

apply(function, args[, keywords])

apply function is used to call any other python function as argument.

Suppose custom function is

custom_function(args)

Need to call function ‘custom_func’ using apply function as follows

apply(custom_function, args)
#!/usr/bin/python                                                          	 
                                                                           	 
def custom_function(arg1, arg2):                                           	 
	print arg1, arg2                                                       	 
                                                                           	 
if __name__ == '__main__':                                                 	 
   apply(custom_function, ("string1", "string2"))                          	 
   apply(custom_function, (5, 5+6))                                        	 
   apply(custom_function, (5.8, 9.3-2.4))

Output:

$ python apply-function.py
string1 string2
5 11
5.8 6.9

Privacy Policy  |  Copyrightcopyright symbol2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^