関数は


最初のオブジェクトである関数によって、
  • 変数
  • への関数の割り当て
    データ構造の
  • ストア機能
  • パスは他の関数
  • に引数として機能します
  • 関数を他の関数からの値として返します.
  • 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")