Joseph Quigley said unto the world upon 2005-04-13 13:05:
def silly(this_is_serious):
print 'this is serious"
But I get an error!
Traceback (most recent call last):
File "C:\Python24\saved\tmp1.py", line 7, in -toplevel-
silly(this_is_serious)
NameError: name 'this_is_serious' is not
Oh, now I understand
def silly(a_name_I_picked_at_random): # well, not
quite
... print
a_name_I_picked_at_random # at random ;-)
...
silly(42)
42
The name a_name_I_picked_at_random is like a "placeholder"
inside the
function for whatever input we gave to the function. And *th
Joseph Quigley said unto the world upon 2005-04-11 20:23:
Well, now I've learned what def is good for. But what could I put in the
parenthesis of def foo():?
Of course self is always available, but what would maybe def
foo(number1): do? An error right? So I now repeat my self, what else
besides
>>> def foo(x):
... print x
...
>>> foo('hi')
hi
What goes in the brackets is simply the arguments that foo() works with.
>>>def foo(a,b):
... return a + b
>>> sum = foo(5,10)
>>>print sum
15
>>> conjun = foo("Hi ", "Dave")
>>>print conjun
Hi Dave
Good luck,
Liam ClarkeOn Apr 12
Well, now I've learned what def
is good for. But what could I put in the parenthesis of
def foo():?
Of course self is always available, but what would maybe
def foo(number1): do? An error
right? So I now repeat my self, what else besides self could I put in
there?
Thanks,
Joseph
__