Ask Your Question

Display variable value

asked 2012-03-27 14:25:40 -0500

richtopia gravatar image

I would like to rapidly report stored values along with the variable name. In python I can do print('A=' + A) for this, which does not seem to work in Sage. Is there a command with this function or a way to fix this print statement?

edit retag flag offensive close merge delete


You can? This doesn't work in Python 2.6, anyway, and yields the expected error. Is it possible that this works in Python 3?

kcrisman gravatar imagekcrisman ( 2012-03-27 15:38:23 -0500 )edit

3 answers

Sort by ยป oldest newest most voted

answered 2012-03-27 15:06:09 -0500

Shashank gravatar image

updated 2012-03-27 15:38:34 -0500

kcrisman gravatar image
print 'A =',A
edit flag offensive delete link more


The initial `var` was erroneous, because the `A=10` cancels that out.

kcrisman gravatar imagekcrisman ( 2012-03-27 15:38:54 -0500 )edit

answered 2012-03-28 02:39:04 -0500

niles gravatar image

print('A=' + A) doesn't work for me in Python 2.6 or 3.2 (unless A happens to be a string). What does work in Python, and in Sage, is print('A=' + str(A)). You have to convert the variable to a string before you can concatenate it with another string.

edit flag offensive delete link more

answered 2012-03-28 10:41:41 -0500

parzan gravatar image

Some options:

sage: print 'A=',A
A= 10
sage: print 'A='+`A`
sage: print 'A=%03d'%A
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-03-27 14:25:40 -0500

Seen: 3,778 times

Last updated: Mar 28 '12