> On Thu, Sep 22, 2011 at 1:37 PM, Anna Haensch <annahaen...@gmail.com> wrote:
> > Is there any way in sage, or rather python, to define a function which
> > takes as its input n variables, rather than assigning a fixed
> > number?
>
> > I've just written a piece of code for the Quadratic Forms module,
> > which takes as input a Quadratic Lattice, Q, and three vectors, so
> > (Q,v_1,v_2,v_3), and it generates the lattice L which is on the same
> > underlying quadratic space as Q but with basis v_1,v_2,v_3.
>

Why not simply use a list v with elements v_1,v_2,...,v_n?

So input (Q, [v_1,v_2,v_3]) into a function
sage: def(Q, v):
....:     # start by unpacking the elements of v
....:

Mike's example would become

sage: def f(v):
....:         return sum(v)
....:
sage: f([1,2,3])
6
sage: f([2,3,5,8])
18







-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to