0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[python] コールバック関数(引数に関数を渡す)

Last updated at Posted at 2020-02-18

#javascriptとpython

javascript
const sayHello = word => console.log(word);
const func = callback => {
  console.log('ここはsayHelloが呼ばれたあとに実行される');
  return callback;
 }

func(sayHello('hello'));
実行結果
hello
ここはsay_somethingが呼ばれたあとに実行される
python
def say_something(word):
    print(word)
    
def func(callback):
    print('ここはsay_somethingが呼ばれたあとに実行される')
    return callback 

func(say_something('hello'))
実行結果
hello
ここはsay_somethingが呼ばれたあとに実行される
0
1
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?