Ask Your Question

Revision history [back]

Hi @omoplata!

This kind of question is fine either here or on sage-support -- which you use is just a matter of your preference.

Practically speaking, there is no difference between the two formats -- they both create a variable x. I think the different usage has to do with the fact that var both creates and returns the variable. So if you type

var('x')

you will get output

x

If you type

x = var('x')

then you are assigning the return value of var('x') to something (x in this case), and hence nothing is printed. This is just like the difference between

sage: 1 + 1
2

and

sage: w = 1 + 1
<nothing printed here>

An amusing side note is that you can make your code more confusing by assigning the return value of var('x') to a different variable:

t = var('x')

Then you can use the variable t, but it will always be printed as x.

sage: y = t^2 + t + 1
sage: y
x^2 + x + 1

I wouldn't really recommend using this ;)

Hi @omoplata!

This kind of question is fine either here or on sage-support -- which you use is just a matter of your preference.

Practically speaking, there is no difference between the two formats -- they both create a variable x. I think the different usage has to do with the fact that var both creates and returns the variable. So if you type

var('x')

you will get output

x

If you type

x = var('x')

then you are assigning the return value of var('x') to something (x in this case), and hence nothing is printed. This is just like the difference between

sage: 1 + 1
2

and

sage: w = 1 + 1
<nothing printed here>

An amusing side note is that you can make your code more confusing by assigning the return value of var('x') to a different variable:

t = var('x')

Then you can use the variable t, but it will always be printed as x.

sage: y = t^2 + t + 1
sage: y
x^2 + x + 1

I wouldn't really recommend using this ;)


Edit: Oh, I see that this question has been answered numerous times since I started composing my overly-long answer; sorry!