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'

 

What Is Wrapper Function

'__dict__' Dictionary in Function Object

Defining Functions in Python

⇑⇑ Python Tutorials

2018-02-08, 1414🔥, 0💬