cannot pass a variable from a function

Grégoire Dooms dooms at info.LESS.ucl.SPAM.ac.be
Thu Jun 17 02:43:16 EDT 2004


Grégoire Dooms wrote:
> If I understand well what you need:
>  >>> def f(a):
>     global q
>     q = a * 80
>     print q
> 
>  >>> def g(l):
>     global q
>     for i in l:
>         q = i * 80

But this should better be implemented as
def g(l):
     global q
       q = l[-1] * 80

Even better:

def g(q,l):
     return l[-1] * 80
# and use as
q = g(q,l)

--
Grégoire Dooms



More information about the Python-list mailing list