[python] Callback function (pass function as argument)

javascript and python

javascript


const sayHello = word => console.log(word);
const func = callback => {
  console.log('This is executed after sayHello is called');
  return callback;
 }

func(sayHello('hello'));

Execution result


hello
Here say_Executed after something is called

python


def say_something(word):
    print(word)
    
def func(callback):
    print('Here say_Executed after something is called')
    return callback 

func(say_something('hello'))

Execution result


hello
Here say_Executed after something is called

Recommended Posts

[python] Callback function (pass function as argument)
Python function argument summary
Use callback function in Python
Function argument type definition in python
python function ①
[Python] function
Basic Python operation 2nd: Function (argument)
python function ②
python enumerate function
Python> function> Closure
[Python] Generator function
Python> function> Inner function
Python function decorator
Example of taking Python> function> * args as arguments
About function arguments (python)
[Python of Hikari-] Chapter 06-02 Function (argument and return value 1)
Function execution time (Python)
Specify a subcommand as a command line argument in Python
Python default argument behavior
Note: The meaning of specifying only * (asterisk) as an argument in the Python function definition.
Today's python error: invalid keyword argument for this function
Python print function (sequel)
Python: About function arguments
A simple difference when passing a pointer as a function argument
Time floor function (Python)
Execute Python function from Powershell (how to pass arguments)
[Python3] Call by dynamically specifying the keyword argument of the function
To return char * in a callback function using ctypes in Python
Python> lambda> tiny functions / callback functions
Create a function in Python
[python] Value of function object (?)
ntile (decile) function in python
[Python] Etymology of python function names
About python beginner's memorandum function
About the enumerate function (python)
python url setting include function
Python #function 2 for super beginners
Nonlinear function modeling in Python
Draw implicit function in python
Python higher-order function (decorator) sample
Immediate function in python (lie)
What is a callback function?
What is the Callback function?
Format when passing a long string as an argument of python
Utilization of lambda (when passing a function as an argument of another function)
I want to pass an argument to a python function and execute it from PHP on a web server