Ask Your Question

Revision history [back]

You can use the solution_dict=True option:

sage: solve([a+b==5,a-b==1],[a, b], solution_dict=True)
[{b: 2, a: 3}]

Here, you get a list of solutions, each solution is a dictionary. You get the first solution (here the only one) with:

sage: solve([a+b==5,a-b==1],[a, b], solution_dict=True)[0]
{b: 2, a: 3}

And it values as:

sage: solve([a+b==5,a-b==1],[a, b], solution_dict=True)[0][a]
3
sage: solve([a+b==5,a-b==1],[a, b], solution_dict=True)[0][b]
2

So, you just have to do:

sage: a = solve([a+b==5,a-b==1],[a, b], solution_dict=True)[0][a]

Also sometimes one gets a == 3 and other times a = 3 why is that?

Are you sure about that ? Could you please provide a way to reproduce, since this is not expected ?