functions and functional programming in this casethe decorators are applied in the order listed the result is the same as thisdef grok( )pass grok foo(bar(spam(grok)) decorator can also accept arguments here' an example@eventhandler('button'def handle_button(msg)@eventhandler('reset'def handle_reset(msg)if arguments are suppliedthe semantics of the decorator are as followsdef handle_button(msg)temp eventhandler('button'handle_button temp(handle_buttoncall decorator with supplied arguments call the function returned by the decorator in this casethe decorator function only accepts the arguments supplied with the specifier it then returns function that is called with the function as an argument here' an exampleevent handler decorator event_handlers def eventhandler(event)def register_function( )event_handlers[eventf return return register_function decorators can also be applied to class definitions for example@foo class bar(object)def _init_ (self, )self def spam(self)statements for class decoratorsyou should always have the decorator function return class object as result code that expects to work with the original class definition may want to reference members of the class directly such as bar spam this won' work correctly if the decorator function foo(returns function decorators can interact strangely with other aspects of functions such as recursiondocumentation stringsand function attributes these issues are described later in this generators and yield if function uses the yield keywordit defines an object known as generator generator is function that produces sequence of values for use in iteration here' an examplef lib fl ff