[Tutor] HELP! How do I remove the black after "s="

Steven D'Aprano steve at pearwood.info
Sat May 10 11:29:30 CEST 2014


Hello "1 2", and welcome!

(By the way, I feel quite silly calling you by the name you show in your 
email address. Do you have another name you would prefer to be known 
by?)

My response below.


On Sat, May 10, 2014 at 02:35:07PM +0800, 1 2 wrote:
> In the result it shows "s= 8" pls tell me how to remove the blank?

There are a few different ways. The easiest is to tell the print() 
function not to use a space as seperator between terms. (This only works 
in Python 3.)

py> print("s=", 8, 9)
s= 8 9
py> print("s=", 8, 9, sep='')
s=89

But note that the separator applies between all the items, so that's not 
very useful in your case. Instead, you can build up a string, then print 
the string. Here are two different ways to do it, the first may be 
familiar with you if you know how to program in C.

py> print("s=%s %s" % (8, 9))
s=8 9
py> print("s={} {}".format(8, 9))
s=8 9


Hope this helps.


-- 
Steven



More information about the Tutor mailing list