Ask Your Question

Revision history [back]

A 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 shotcut:

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 is the Python name
a              # this is the symbol

A 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 shotcut:

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 is the Python name
a              # this is the symbol

A 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 shotcut:

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 is the a is a Python name
a              # this is the symbol
a is a symbol, pointed bythe previous Python name

A 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 shotcut: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 name