[Tutor] The def command

Ivan Van Laningham ivanlan@callware.com
Wed, 13 Oct 1999 15:07:48 -0600


Hi All--


You asked this earlier, as "how do I use the __def__ command to create
an object."


Alexandre Passos wrote:
> 
> How can I use the def command to create an object?
> 

Def is not a command.  It's a statement.  You use it to create function
objects.  Like this:

def myfunction(s):
        print s

Then you can call it like this:

if __name__ == "__main__":
        myfunction("Hello, world!")

You can also do things like this:

xx = myfunction

(note the absence of parentheses after the name of the function; parens
after an object mean it is callable, like a function.)

Then, you can do things like this:

xx("Goodbye, Cruel World!")

If you want to know about objects like classes, look at the docs at
www.python.org, or as the tutor list some more specific question.

<ave-atque-vale-perfidium-orbum>-ly y'rs,
Ivan
----------------------------------------------
Ivan Van Laningham
Callware Technologies, Inc.
ivanlan@callware.com
ivanlan@home.com
http://www.pauahtun.org
See also: 
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps:  Cu Chi, Class of '70
----------------------------------------------