Input Types
Jeff Epler
jepler at unpythonic.net
Sat May 15 14:59:53 EDT 2004
On Sat, May 15, 2004 at 08:23:51PM +0200, moma wrote:
> You can send functions (int, float) and exceptions as parameters?
> Amazing.
You sure can.
numbers, sequences, dicts, functions, exceptions, classes, modules: all
these things are objects, and you can pass any object you like as a
parameter. Of course, not all object types *make sense* everywhere!
One "exception" to this rule is thinking that print is a function, and
trying to write
def send_to(value, action):
return action(value)
def f(x): return x*x
>>> send_to(3, f) # square the argument: works
9
>>> send_to(3, print) # Print the argument: error
File "<stdin>", line 1
send_to(3, print)
^
SyntaxError: invalid syntax
because print is a statement, not a function, this isn't really an
exception to the rule at all.
Jeff
More information about the Python-list
mailing list