Change default power operator output to '**' rather than '^' .

40 views
Skip to first unread message

John Atom

unread,
May 1, 2020, 3:30:10 PM5/1/20
to sage-support
If I define a function: 

f(x) = x**2

and then print it, sage always prints it as `x^2`. 

Is it possible to change the default output of the power operator to '**' ? 

I'd like to use Sage to create and manipulate functions, but then copy the output to other python applications that do not recognize the '^' symbol as the power operator.

Thanks. 

Nils Bruin

unread,
May 1, 2020, 6:26:47 PM5/1/20
to sage-support
On Friday, May 1, 2020 at 12:30:10 PM UTC-7, John Atom wrote:
If I define a function: 

f(x) = x**2

and then print it, sage always prints it as `x^2`. 

Is it possible to change the default output of the power operator to '**' ? 

I suspect it will be hard, because these "^" are coming from lots of places, including third party libraries that know how to produce a string representation of their internal representation. I think:

str(f).replace('^','**')

is going to be the most reliable way of accomplishing this.
 

John Atom

unread,
May 1, 2020, 7:12:12 PM5/1/20
to sage-support
That works. Thank you. 
Reply all
Reply to author
Forward
0 new messages