generators instead of returning single valuea function can generate an entire sequence of results if it uses the yield statement for exampledef countdown( )print "counting down!while yield generate value (nn - any function that uses yield is known as generator calling generator function creates an object that produces sequence of results through successive calls to next(method (or _next_ (in python for examplec countdown( next(counting down next( next( the next(call makes generator function run until it reaches the next yield statement at this pointthe value passed to yield is returned by next()and the function suspends execution the function resumes execution on the statement following yield when next(is called again this process continues until the function returns normally you would not manually call next(as shown insteadyou hook it up to for loop like thisfor in countdown( )print icounting down generators are an extremely powerful way of writing programs based on processing pipelinesstreamsor data flow for examplethe following generator function mimics the behavior of the unix tail - command that' commonly used to monitor log filestail file (like tail -fimport time def tail( ) seek( , move to eof while trueline readline(try reading new line of text if not lineif nothingsleep briefly and try again time sleep( continue yield line here' generator that looks for specific substring in sequence of linesdef grep(linessearchtext)for line in linesif searchtext in lineyield line lib fl ff