Friday, October 2, 2009

Function Definitions

Function definitions are really hard to understand just from the book. I didn't get the whole "bruce" thing. I think I get it now, though.
A function definition is like a variable for a function. For ex/
if you type
def print_twice(x):
print x, x

then
print_twice('dog')

it will print
dog dog

The statement (print_twice) is a variable for the function (print x, x). The parameters(x) are variables that change the result of the function depending on what you enter into the parenthesis. ('dog') prints dog, dog if I type ('cat') it prints cat, cat.

That's how I would explain function definitions at least.

2 comments:

  1. Since both you and Louie had the same reaction to the presentation of functions in chapter 2, I'm going to take another look at that and try to edit it for clarity.

    I won't be able to ask you if it is better, since you will not be able to look at with with "beginner's eyes" any more.

    Thanks for the feedback.

    ReplyDelete
  2. Wonderful reflection! Actually, both variables and functions are examples of one of the most powerful things that we humans do: the power of abstraction.

    Variables abstract values or expressions, while functions abstract processes.

    ReplyDelete