[Tutor] function declaration problems perhaps?
Tiger12506
keridee at jayco.net
Thu Jul 26 00:33:05 CEST 2007
> By the way, this is an important and fundamental subject about
> Python. When I teach classes on Python, I always need to explain
> Python's execution model, and I always struggle with it. So,
> anything you can tell me that would help me teach this will be much
> appreciated.
>
> Dave
The way I keep it clear is simple. If python needs the value of the name (it
has to look it up) then it had better be defined. Otherwise ~ It doesn't
matter!
Think of it like assignment.
x = 1
Does python need to know the current value of x? No. Then x does not have to
be previously defined.
f()
Does python need to know the current value of f? Yes. It has to know that f
is a function, and where the address is, etc.
def f1():
f()
Does python need to know the current value of f? No. Not until f1 is
executed.
Does this help? Only one rule to remember. ;-) ~Does python need to know the
value of _this_ variable?~
JS
More information about the Tutor
mailing list