cannot pass a variable from a function
Porky Pig Jr
porky_pig_jr at my-deja.com
Thu Jun 17 00:48:41 EDT 2004
"Doug Jordan" <djordan8 at houston.rr.com> wrote in message news:<m54Ac.3645$4g1.791 at fe2.texas.rr.com>...
> I am fairly new to Python. This should be an easy answer but I cannot get
> this to work. The code is listed below. I know how to do this in C,
> Fortran, and VB but it doesn't seem to work the same way here.
> I would appreciate any help.
>
> #try this to pass a list to a function and have the function return
> #a variable
> #this works
> list=[1,4,6,9]
> def fctn(c):
> for h in c:
> q=h*80
> print q
You know, I am also new to Python, and fairly well versed in C, but
don't you think that the following function:
> #function suppose to return variable
> def fctn2(c):
> for h in c:
> q=h*80
> return q
will return whatever it gets on a very first iteration so it will
return a scalar 1*80 rather than list I assume you are trying to
return.
You probably need something like this:
def fctn2(c):
return [h * 80 for h in c]
Once again, you didn't make it quite clear what is that exaclty you
are trying to return, so I assume you are trying to return a list,
rather than scalar.
More information about the Python-list
mailing list