Definition statement

Richard Jones richard at bizarsoftware.com.au
Fri Aug 17 03:31:16 EDT 2001


On Friday 17 August 2001 17:04, Patio87 wrote:
> Im am learning python right know and I have come to a chapter called
> functions and procedures. It goes into detail about the "def" function. I
> canoont seem to understand what it does. can someone please tell me what it
> means.

OK, "def" isn't a function, it's a statement. It's there to tell the language 
to do something, and in this case it's to DEFine a function. The statement:

>>> def foo():
...   print 'hi mum'
... 
>>> foo
<function foo at 0x81331c4>

defines a function called "foo". The function "foo" may then be called like 
so:

>>> foo()
hi mum
>>> 


    Richard

ps. note, in the above, you see the ">>>" and "..." of the python interpreter 
in interactive mode - the best way to learn Python. Just run "python" and 
type in the stuff I typed above, and you should get the same results.





More information about the Python-list mailing list