関数は
4220 ワード
最初のオブジェクトである関数によって、変数 への関数の割り当て
データ構造のストア機能 パスは他の関数 に引数として機能します関数を他の関数からの値として返します.
データ構造の
Assignment
def yell(text):
return text.upper() + '!'
bark = yell
bark('woof')
Functions can be stored in data structures
funcs = [str.lower, str.capitalize]
for f in funcs:
print(f('hey there'))
Functions can be passed to other functions
def yell(text):
return text.upper() + '!'
map(yell, ['hello', 'hey', 'hi'])
Functions can be returned from other functions
def talk(volume):
def whisper(text):
return text.lower() + '...'
def yell(text):
return text.upper() + '!'
if volume > 0.5:
return yell
else:
return whisper
talk(0.8)("hello")
Reference
この問題について(関数は), 我々は、より多くの情報をここで見つけました https://dev.to/icncsx/functions-are-first-class-objects-1dmbテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol