Reputation: 173
When I use the code in python 2.7.5
for i in [1,2]:
print 'distance',':400@CA',':',i,'@CA'
I got the following
distance :400@CA : 1 @CA
distance :400@CA : 2 @CA
I want to remove the space (eg., among :,1,@CA) so that the output will be like
distance :400@CA :1@CA
distance :400@CA :2@CA
I also tried using sep='' or end='' but still they don't work. Any suggestion will be appreciated.
Upvotes: 0
Views: 213
Reputation: 318
Use the sep tag in print
from __future__ import print_function
print('distance',':400@CA',':',i,'@CA', sep = '')
Upvotes: 0
Reputation: 202
for i in [1,2]:
print 'distance',':400@CA',':'+str(i)+'@CA'
Output: distance :400@CA :1@CA
distance :400@CA :2@CA
Using ,(comma) will add space while printing. Better concatenate using +
Upvotes: 0
Reputation: 500367
I'd use the string formatting operator %
:
for i in [1,2]:
print 'distance :400@CA :%d@CA' % i
This gives you quite a lot of control over how things are laid out.
Upvotes: 2
Reputation: 29064
You can use %d operator:
for i in [1,2]:
print 'distance',':400@CA',':','%d@CA' % i
Or you can use join:
for i in [1,2]:
print 'distance'+':400@CA:'.join(i,'@CA')
With reference to:How to print a string of variables without spaces in Python (minimal coding!)
Hope this helps...
Upvotes: 1