LoginSignup
0
0

More than 5 years have passed since last update.

Python > function > functionを引数に取る例 > map(lambda x: 2 ** x, [1, 2, 3]) / locals()['myprint'](3.1415, 2.718) を教えていただきました

Last updated at Posted at 2017-04-04

@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic
(No. 2652 / 12833)

functionを引数として渡す例がある。

試してみた。

def myfunc(fnc, arg1, arg2):
    fnc(arg1, arg2)

def myprint(arg1, arg2):
    print('%s,%s' % (arg1, arg2))

myfunc(myprint, 3.1415, 2.718)
結果
Success time: 0 memory: 23304 signal:0
3.1415,2.718

標準ドキュメントはこのあたりが関係しそう?
引数の解釈と値の構築

教えていただいた事項

@shiracamus さんのコメントにてmap()を使った関数の実行方法について教えていただきました。

また、こちらのコメントにてローカル変数辞書からfunction nameをキーとして呼び出し、実行する方法を教えていただきました。

情報感謝です。

0
0
6

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
0