Ask Your Question
0

Display variable value

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

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

Comments

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 -0600 )edit

3 answers

Sort by ยป oldest newest most voted
1

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

Shashank gravatar image

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

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

Comments

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

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

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

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
0

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

parzan gravatar image

Some options:

sage: print 'A=',A
A= 10
sage: print 'A='+`A`
A=10
sage: print 'A=%03d'%A
A=010
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

Stats

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

Seen: 2,408 times

Last updated: Mar 28 '12