Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. I check, compile and run every program. Contact me at: aviboots(AT)netvision.net.il
Hostgator 1 Penny

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


6,849 questions

9,751 answers

573 users

How to use function as parameter in Python

2 Answers

0 votes
def test():
    print("test()")


def f(func):
    print("f()")
    print("call func()")
    func()  # test()

f(test)


'''
run:

f()
call func()
test()

'''

 




answered Dec 19, 2017 by avibootz
0 votes
import math


def f(func):
    print("function: " + func.__name__)
    return func(3.14)

print(f(math.cos))
print(f(math.sin))


'''
run:

function: cos
-0.9999987317275395
function: sin
0.0015926529164868282

'''

 




answered Dec 19, 2017 by avibootz
...