but they do lead us to some bigger programming ideas coding functions although it wasn' made very formalwe've already used some functions in earlier for instanceto make file objectwe called the built-in open functionsimilarlywe used the len built-in function to ask for the number of items in collection object in this we will explore how to write new functions in python functions we write behave the same way as the built-ins we've already seenthey are called in expressionsare passed valuesand return results but writing new functions requires the application of few additional ideas that haven' yet been introduced moreoverfunctions behave very differently in python than they do in compiled languages like here is brief introduction to the main concepts behind python functionsall of which we will study in this part of the bookdef is executable code python functions are written with new statementthe def unlike functions in compiled languages such as cdef is an executable statement--your function does not exist until python reaches and runs the def in factit' legal (and even occasionally usefulto nest def statements inside if statementswhile loopsand even other defs in typical operationdef statements are coded in module files and are naturally run to generate functions when the module file they reside in is first imported def creates an object and assigns it to name when python reaches and runs def statementit generates new function object and assigns it to the function' name as with all assignmentsthe function name becomes reference to the function object there' nothing magic about the name of function--as you'll seethe function object can be assigned to other namesstored in listand so on function objects may also have arbitrary user-defined attributes attached to them to record data lambda creates an object but returns it as result functions may also be created with the lambda expressiona feature that allows us to in-line function definitions in places where def statement won' work syntactically this is more advanced concept that we'll defer until return sends result object back to the caller when function is calledthe caller stops until the function finishes its work and returns control to the caller functions that compute value send it back to the caller with return statementthe returned value becomes the result of the function call return without value simply returns to the caller (and sends back nonethe default resultyield sends result object back to the callerbut remembers where it left off functions known as generators may also use the yield statement to send back coding functions