[Tutor] Equivalent of a Subroutine in Python?
Thu, 1 Feb 2001 09:54:04 -0800 (PST)
On Wed, 31 Jan 2001, Seelinger, Bruce wrote:
> Another question from someone totally new to Python. Is there an
> equivalent in Python to a sub-routine, (e.g. gosub and return).
There are functions.
> I want to create a modular program with sub-routines to perform
> distinct tasks wihin the program for organizational and debugging
> purposes, etc. Is the only (or best) way to do this is with modules?
No. As I said, there are also functions.
> A function works but the values obtained within the function do not
> appear to be valid outside of that function. I guess I am looking for
> the best approach to create the subroutines for execution from the
> main flow of the program.
Good coding design says that that's the way it should be. Functions should
only change what's inside them, not stuff that may have Unintended
Clearly, you learned Basic first and early versions of Basic (sorry, I
haven't used the language in 26 years...) didn't have local scoping as
that was difficult to implement and its advantages were not yet
appreciated. I believe Pascal was the first widely-used language to use