ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 12 May 2020 18:26:32 +0200Desattribution of a value to a variablehttps://ask.sagemath.org/question/51389/desattribution-of-a-value-to-a-variable/ Suppose I have attributed to `a` the value 3. But for the following operation I want to use anew `a` as a variable how should I operate, redefine `a` ?Tue, 12 May 2020 16:53:36 +0200https://ask.sagemath.org/question/51389/desattribution-of-a-value-to-a-variable/Answer by tmonteil for <p>Suppose I have attributed to <code>a</code> the value 3. But for the following operation I want to use anew <code>a</code> as a variable how should I operate, redefine <code>a</code> ?</p>
https://ask.sagemath.org/question/51389/desattribution-of-a-value-to-a-variable/?answer=51394#post-id-51394A Python name is just a pointer to a Python/Sage object:
sage: a = 3
sage: a+a
6
Now, if you redefine it, it will just point to the new object:
sage: a = 12
sage: a
12
sage: a^2
144
If you want the symbol `a` (not to be confused with the Python name `a`), you can do:
sage: SR.var('a')
a
Any Python name can point to such symbol:
sage: b = SR.var('a')
sage: b
a
sage: (b+1)^2
(a + 1)^2
What confuses most people is that the shortcut:
sage: var('a')
a
both returns the symbol `a` and let the Python name `a` point to this symbol, in particular, it removes the previous pointer of the Python name `a` :
sage: a # this a is a Python name
a # this a is a symbol, pointed bythe previous Python nameTue, 12 May 2020 18:26:32 +0200https://ask.sagemath.org/question/51389/desattribution-of-a-value-to-a-variable/?answer=51394#post-id-51394