Pass Function as Function Parameter

Q

How to pass function objects as function parameters?

✍: FYIcenter.com

A

You can pass function objects like any other types of objects as parameters of other functions.

For example,

>>> def x():
...    print("Hello world!")
...
>>> def addVersion(f):
...     f.version = "1.0"
...     f.author = "FYIcenter.com"
...     return f
...
>>> y = addVersion(x)
>>> x.version
'1.0'
>>> y.version
'1.0'

 

Defining Functions in Python

⇒⇒Python Tutorials

2017-09-12, 110👍, 0💬