Ask Your Question

Revision history [back]

If you do not want to print a new line after each print command, just add a comma after the print command:

sage: print 1 ; print ')' ; print 3
1
)
3
sage: print 1, ; print ')', ; print 3,
1 ) 3

Note that it is Python2 specific, so that when Sage will be using Python 3, you will have to write print(my_string, end='')

If you do not want to print a new line after each print command, just add a comma after the print command:

sage: print 1 ; print ')' ; print 3
1
)
3
sage: print 1, ; print ')', ; print 3,
1 ) 3

Note that it is Python2 specific, so that when Sage will be using Python 3, you will have to write print(my_string, end='')

That said, as suggested by @krismann, i would better suggest to construct a single string and return it at the end. You can concatenate strings as follows:

sage: a = ''
sage: a += '1'
sage: a += ')'
sage: a += '3'
sage: a
'1)3'
sage: print a
1)3