Ask Your Question
0

Display variable value

asked 2012-03-27 21:25:40 +0200

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 22:38:23 +0200 )edit

3 Answers

Sort by ยป oldest newest most voted
1

answered 2012-03-27 22:06:09 +0200

Shashank gravatar image

updated 2012-03-27 22:38:34 +0200

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 22:38:54 +0200 )edit
1

answered 2012-03-28 09:39:04 +0200

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 17:41:41 +0200

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 21:25:40 +0200

Seen: 11,358 times

Last updated: Mar 28 '12