Page 146 -
P. 146

functions


                              Your Programming Toolbox


                               You’ve got Chapter 3 under your
                               belt. Let’s look back at what
                               you’ve learned in this chapter:                                                  CHAPTER 3








                  Programming T ools




                   * Avoid code duplication with functions.
                    * Parameters are variables that you can pass to



                     functions.
                     * Functions can return values.
                      * Computers use stack frames to record and


                       * When you call a function, a new stack frame is
                      track variables.                               Python T ools
                       created for the function to use.
                        * Stack frames (and local variables) are thrown


                         away when you exit a function.
                         * A variable is said to be “in scope” whenever it's

                         value can be seen by some code.
                                                                    * Use “def" to create functions.
                                                                    * Use return() to send a value
                                                                    back to the code that called the
                                                                    function.

                                                                   * Pass parameters to functions by
                                                                   placing them between parentheses.











                                                                                       you are here 4    111
   141   142   143   144   145   146   147   148   149   150   151