[Tutor] defining functions

alan.gauld@bt.com alan.gauld@bt.com
Mon, 10 Dec 2001 11:58:23 -0000

> Gang, in some languages you MUST define somethign before 
> using it, in others no, as long as it is defined 

In Python you can reference it before its defined but you cant execute it.


def func1():
   print "func2 says: %d" % func2()  # refer to func 2 before defining

# func1()  # ERROR cause func2 now gets called before being defined!

def func2(): return 42

func1()  # Now OK cause func2 exists.

Does that help?

Alan G.
> In PASCAL one must define anything and everything before using it

Good practice and the reason why, once you get a Pascal program 
to compile it usually runs pretty much as you expect!

And that, after all, was the whole purpose of Pascal 
- to teach good programming practice!

Alan g.