Thanks Samuel and Emmanuel.

Follow up question:  Why does
var('lambda',n=1)
fail?

I know that the name "lambda" is not a valid Python identifier, but I am
asking for "lambda0", "lambda1".

Guillermo

On Tue, 8 Mar 2022 at 19:19, Emmanuel Charpentier <
emanuel.charpent...@gmail.com> wrote:

> even more simpler :-) :
>
> sage: V=var("v", n=8)
> sage: V
> (v0, v1, v2, v3, v4, v5, v6, v7)
> sage: v2
> v2
> sage: V[2]
> v2
>
> *“Who could ask for anything mooooore ?”*
> Le mardi 8 mars 2022 à 08:20:07 UTC+1, slelievre a écrit :
>
>> Even more practical, I find, is to name the tuple of indexed variables:
>> ```
>> sage: v = SR.var('v', n=8)
>> sage: v
>> (v0, v1, v2, v3, v4, v5, v6, v7)
>> ```
>> and to use index notation `v[k]` instead of `vk` to use the variables.
>> ```
>> sage: v[0]
>> v0
>> sage: v[7]
>> v7
>> ```
>>
>> That does not assign the variables to the names `v0` to `v7`:
>> ```
>> sage: v2
>> Traceback (most recent call last)=
>> ...
>> NameError: name 'v2' is not defined
>> ```
>>
>> If you really want to use `v0` to `v7` instead of `v[0]` to `v[7]`,
>> follow the implementation in `var` (accessed with `var??`),
>> which simply amounts to:
>> ```
>> G = globals()
>> for vk in v:
>>     G[repr(vk)] = vk
>> ```
>>
>> After that:
>> ```
>> sage: v2
>> v2
>> ```
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/CANnG18_%2BFg%2B5xuwgJBN_-HH5UgGnmCwdz_3si10hgfv3HhU8tA%40mail.gmail.com.

Reply via email to