[Tutor] Can I use def without ( ) at the end?

Alan G alan.gauld at freenet.co.uk
Sun Jul 10 10:03:44 CEST 2005


Nathan,

>  How do I make Python get a def? Is it the "get" function, or 
> something
>  else? I need to know so that I can get a def for that computer
>  MasterMind(tm) game that I'm writing.

This sounds like you really don't understand what def does.
Can I suggest you take time out to read about functions in one
of the tutorials, it will likely save a lot of time in the long run.

You can try my tutorial "Modules and Functions" is the topic,
or the official tutorial, or virtually any other.

>  BTW, I took your advice, and wrote some definitions for my Giant
>  Calculator program.

def is not a definition in the general sense, it is a function
definition. You call functions with parens and get a result back.
Your earlier questions showed that you don't really understand
that concept yet.

>  Might make the code easier to read, but harder to code
>  because I have to keep going to the top to read the menu. Not that 
> fun,

If your editor supports split screens (eg. emacs, vim)  then you
can simply do that and have the top 'frame' display the menu.

Other common tricks include setting a bookmark at the menu and
using the goto bookmark feature(if you have one) to jump straight
there and then go to bottom to get back to your new code.

If you have a folding editor like Scite (or Pythonwin) then
you can collapse all definitions except the menu and the one you are
working on which is often enough too.

Finally you can always open two editor sessions on the same file,
one for reading and one for working in.

Lots of options depending on your tools.

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld 



More information about the Tutor mailing list