easy question, how to double a variable

Tim Chase python.list at tim.thechases.com
Mon Sep 21 22:50:13 EDT 2009


> But you actually want to return twice the value. I don't see
> how to do that.


Ah, I think I see...returning more than once is done with the 
"yield" keyword:

   def f(param):
     yield param
     yield param

That returns twice the integer parameter... :-D

However, the OP was instructed to "Write the definition of a 
function twice" which means I'd have to copy & paste the final 
function definition a second time to make sure it was done twice 
(as Carl suggested).

Then again as David notices, the subject lines asks how to double 
a variable, in which case one might want

   import struct
   def f(param):
     return struct.pack('f', param)

which doubles the parameter... :-S

-tkc







More information about the Python-list mailing list